MATLAB Help converting MATLAB to Scilab code

  • Thread starter Thread starter DiracPool
  • Start date Start date
  • Tags Tags
    Code Matlab
AI Thread Summary
The discussion revolves around converting MATLAB code for a spiking neuron program to Scilab, specifically addressing issues with graphing results. The user encountered problems with the line of code that appends data to a matrix for plotting, which works in MATLAB but not in Scilab. Suggestions include using the Scilab 'Matlab to Scilab Translator' and noting differences in function behavior between the two languages, such as randn() and find(). A user shared their experience running the program on a free online MATLAB version, noting that changing the plot syntax helped generate a graph, though it did not match the expected output. Ultimately, the user found success by using the online MATLAB and later installing Octave, which worked seamlessly for their needs, highlighting the importance of alternative tools in overcoming coding challenges.
DiracPool
Messages
1,242
Reaction score
515
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?
 
hutchphd said:
Line 14 of what?
Of the MATLAB code on page 1571 the article: https://www.izhikevich.org/publications/spikes.pdf

The lines aren't numbered, but it's about 14 lines down... firings=[firings; t+0*fired,fired];
 
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:
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 Steve4Physics

Similar threads

Replies
5
Views
3K
Replies
32
Views
4K
Replies
1
Views
2K
Replies
3
Views
2K
Replies
1
Views
4K
Replies
5
Views
3K
Replies
5
Views
1K
Back
Top