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
1,232
513
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:
  • #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

1. How do I convert MATLAB code to Scilab code?

There are a few ways to convert MATLAB code to Scilab code. One option is to manually translate the code line by line, keeping in mind any differences in syntax and function names between the two languages. Another option is to use a code conversion tool specifically designed for this purpose.

2. Are there any major differences between MATLAB and Scilab?

While both MATLAB and Scilab are high-level programming languages used for scientific computing, there are some key differences between them. These include differences in syntax, available functions, and the way in which variables are handled.

3. Can I use all of my MATLAB code in Scilab?

Not all MATLAB code can be directly translated to Scilab. Some functions in MATLAB may not have equivalent functions in Scilab, and certain syntax may need to be modified. It's important to thoroughly test and debug your code after converting it to ensure it functions correctly in Scilab.

4. Is it possible to automate the conversion process?

Yes, there are some tools and scripts available that can help automate the process of converting MATLAB code to Scilab. However, it's important to note that these tools may not always provide perfect translations, so manual checking and debugging may still be necessary.

5. Can I still use my MATLAB code after converting it to Scilab?

Yes, you can still use your MATLAB code after converting it to Scilab. However, it's important to keep in mind that there may be differences in performance and functionality between the two languages, so it's best to thoroughly test and debug your code in Scilab to ensure it produces the desired results.

Suggested for: Help converting MATLAB to Scilab code

Replies
1
Views
2K
Replies
1
Views
1K
Replies
1
Views
687
Replies
12
Views
2K
Replies
2
Views
1K
Replies
3
Views
1K
Back
Top