Help converting MATLAB to Scilab code

  • MATLAB
  • Thread starter DiracPool
  • Start date
  • Tags
    Code Matlab
In summary, the problem is with graphing the results of a spiking neuron program. The lines aren't numbered, but it's about 14 lines down on page 1571 of the article. 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.
  • #1
DiracPool
1,243
516
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
  • #2
Line 14 of what?
 
  • #3
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];
 
  • #4
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 DiracPool
  • #5
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

FAQ: Help converting MATLAB to Scilab code

How do I convert MATLAB code to Scilab code?

To convert MATLAB code to Scilab code, you can use the built-in function "mfile2sci" in Scilab. This function automatically converts MATLAB code to Scilab code and saves it in a new file. You can also manually rewrite the code using the Scilab syntax.

Can I convert all types of MATLAB code to Scilab?

While most MATLAB code can be converted to Scilab, there may be some functions or syntax that are not supported in Scilab. It is recommended to check the Scilab documentation or ask for help in online forums if you encounter any errors or issues during the conversion process.

Will my Scilab code produce the same results as my MATLAB code?

In most cases, the results from the converted Scilab code should be the same as the original MATLAB code. However, there may be slight differences due to differences in the underlying algorithms or functions used in each software. It is important to carefully test and validate your results to ensure accuracy.

Is there a way to automate the conversion process for large MATLAB code files?

Yes, there are tools available that can help automate the conversion process for large MATLAB code files. Some examples include the "mfile2sci" function in Scilab or external conversion software such as "Matlab2Scilab" or "Matlab2Scilab converter". It is recommended to test the converted code for accuracy after using these tools.

Can I use Scilab code in place of MATLAB code in my research or projects?

Yes, you can use Scilab code in place of MATLAB code for your research or projects. However, it is important to note that there may be differences in the syntax and functions used in each software, so it is recommended to carefully test and validate your results before using them in your work.

Similar threads

Replies
3
Views
2K
Replies
1
Views
4K
Replies
5
Views
2K
Replies
5
Views
1K
Replies
3
Views
4K
Replies
12
Views
3K
Replies
9
Views
4K
Back
Top