Help converting MATLAB to Scilab code

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

Discussion Overview

The discussion revolves around the challenges of converting MATLAB code to Scilab code, specifically in the context of graphing results from a spiking neuron program. Participants explore issues related to syntax differences and functionality between the two programming environments.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Exploratory

Main Points Raised

  • One participant expresses difficulty with a specific line of MATLAB code that does not translate well to Scilab, particularly in establishing a matrix for plotting.
  • Another participant questions which line of code is being referred to, seeking clarification on the specific MATLAB code in question.
  • A participant suggests that changes are necessary when translating MATLAB to Scilab, noting differences in functions like randn() and find().
  • One participant shares their experience running the MATLAB code and modifying the plot command to achieve a graph, although the result did not match the expected figure from the paper.
  • Concerns are raised about the dimensionality of variables in the referenced paper, highlighting potential inconsistencies in the treatment of variables as dimensionless or having units.
  • A participant reports success in running the program on an online MATLAB platform after removing comments from the code, and mentions downloading Octave as an alternative that worked well for them.

Areas of Agreement / Disagreement

The discussion contains multiple competing views regarding the translation process and the effectiveness of different tools. There is no consensus on a single solution to the problem presented.

Contextual Notes

Participants note limitations in their knowledge of both MATLAB and Scilab, which may affect the accuracy of their suggestions. There are also unresolved questions about the translation of specific functions and the implications of variable dimensions in the referenced paper.

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 4 ·
Replies
4
Views
2K
  • · 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