Help converting MATLAB to Scilab code

  • Context: MATLAB 
  • Thread starter Thread starter DiracPool
  • Start date Start date
  • Tags Tags
    Code Matlab
Click For Summary
SUMMARY

This discussion focuses on converting MATLAB code to Scilab, specifically addressing issues with graphing results from a spiking neuron program. The user encountered problems with the line firings=[firings; t+0*fired,fired]; and plotting using plot(firings(:,1),firings(:,2),'.');. Solutions included using the Scilab 'Matlab to Scilab Translator' and testing the code in a free online MATLAB environment. Ultimately, the user found success by using GNU Octave, which has similar syntax to MATLAB, allowing the program to run correctly without limitations.

PREREQUISITES
  • Familiarity with MATLAB syntax and functions, particularly randn() and find().
  • Understanding of Scilab and its differences from MATLAB.
  • Basic knowledge of plotting functions in MATLAB and Scilab.
  • Experience with GNU Octave as an alternative to MATLAB.
NEXT STEPS
  • Explore the 'Matlab to Scilab Translator' tool in Scilab for code conversion.
  • Learn how to effectively use GNU Octave for MATLAB-like functionality.
  • Investigate differences in function behavior between MATLAB and Scilab, focusing on find() and randn().
  • Research best practices for plotting in Scilab to ensure accurate graph representation.
USEFUL FOR

This discussion is beneficial for software developers, neuroscientists, and researchers transitioning from MATLAB to Scilab or Octave, particularly those working with spiking neuron models and graphing data.

DiracPool
Messages
1,247
Reaction score
514
Hello, I am having difficulty converting some MATLAB code to Scilab code. Specifically, the problem is with graphing the results of a spiking neuron program. Herer is the program and the article that explains it:

https://www.izhikevich.org/publications/spikes.pdf

The problem I am having is around line 14:

firings=[firings; t+0*fired,fired];

This does not establish a matrix that can be plotted as executed in the last line of the program:

plot(firings(:,1),firings(:,2),'.');

This works in MATLAB but not in Scilab and I haven't found a fix. Please help!
 
Physics news on Phys.org
Line 14 of what?
 
Hi @DiracPool .A few thoughts if you are still struggling with this…

My knowledge of MATLAB is very (and I mean very) limited. And my knowledge of Scilab is significantly less!

To run the MATLAB program under Scilab, changes are needed. But you didn’t say what changes you’ve made. For example, the function randn(), is used in MATLAB, but not Scilab; the function find() in MATLAB may work slightly differently to find() in Scilab.

Have you already translated the MATLAB code to Scilab? If not, look at the ‘Application' drop-down menu at the top of the Scilab Console window. The menu contains ‘Matlab to Scilab Translator’. Never used it myself but it might do the job.

For interest I copied/pasted the program in the link and ran it on (a free online version of) MATLAB. It didn’t work. After a bit of puzzling I changed
plot(firings(:,1),firings(:,2), ‘.’)
to
plot(firings(:,1),firings(:,2), “.”).
and got a graph - but the graph didn’t look like Figure 3!

I also skimmed through the paper out of interest. The text says ##u## and ##v## are dimensionless variables. But equation 3 says ##v \ge 30mV## which means ##v## would have dimensions (it is a voltage). And ##u## would then have to have units of mV/s to make equation 1 homogeneous. But then ##u## is treated as a voltage later on.

However, mustn’t be picky!

Edit - typo'.
 
Last edited:
  • Like
Likes   Reactions: DiracPool
Steve4Physics said:
Hi @DiracPool .A few thoughts if you are still struggling with this…

My knowledge of MATLAB is very (and I mean very) limited. And my knowledge of Scilab is significantly less!

To run the MATLAB program under Scilab, changes are needed. But you didn’t say what changes you’ve made. For example, the function randn(), is used in MATLAB, but not Scilab; the function find() in MATLAB may work slightly differently to find() in Scilab.

Have you already translated the MATLAB code to Scilab? If not, look at the ‘Application' drop-down menu at the top of the Scilab Console window. The menu contains ‘Matlab to Scilab Translator’. Never used it myself but it might do the job.

For interest I copied/pasted the program in the link and ran it on (a free online version of) MATLAB. It didn’t work. After a bit of puzzling I changed
plot(firings(:,1),firings(:,2), ‘.’)
to
plot(firings(:,1),firings(:,2), “.”).
and got a graph - but the graph didn’t look like Figure 3!

I also skimmed through the paper out of interest. The text says ##u## and ##v## are dimensionless variables. But equation 3 says ##v \ge 30mV## which means ##v## would have dimensions (it is a voltage). And ##u## would then have to have units of mV/s to make equation 1 homogeneous. But then ##u## is treated as a voltage later on.

However, mustn’t be picky!

Edit - typo'.
Hi Steve, thanks for the reply and the leads. The translation/converter tool in Scilab did not seem to work, it didn't even produce a file that could even be run. What really helped was your mention of the free online MATLAB. That's pretty cool. At 20 hours a month, that might be all I need for that project. Plus, I'm actually downloading the free "Octave" alternative right now since I heard that the syntax is almost identical to MATLAB. So we will see if that does the trick.

By the way, I was able to get the program to run correctly on the Free online MATLAB. What worked for me was to delete all the comments (i.e. what comes after "//"). Try it and see if it works for you. It's a cool program to fool around with if you're into neuroscience.

11:33pm One final edit, haha. I just finished installing Octave and ran the program. Works perfectly...Success! Not even a 20 hour limit. Thanks again!
 
Last edited:
  • Like
Likes   Reactions: Steve4Physics

Similar threads

Replies
6
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 0 ·
Replies
0
Views
145
  • · Replies 1 ·
Replies
1
Views
4K
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 12 ·
Replies
12
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 14 ·
Replies
14
Views
4K