I apologize in advance for this question. I don't like "explain this code" questions, but I can't find any documentation about my specific example.
Background
My issue is this. I am trying to translate some MATLAB code to C#, but I am at the same time having to learn MATLAB. I do not work with anyone that knows MATLAB code, I have no access to MATLAB, so I can't test any of the code, and I can't find any documentation on the following question. So...
Question(s)
Is there a free online/desktop MATLAB compiler/interpreter somewhere that I can use to test out MATLAB code?
...or...
Is there someone that can explain the following code snippet:
someVar.member1=myValue1;
someVar.member2=myValue2;
if (myCondition)
for i=1:myTotal
someVar(i).member3=myValue3;
end;
end;
Does this make someVar
into an array? Do I lose member1
and member2
or does it save what I have set somehow?
No Downloads or Installations MATLAB® Online™ provides access to MATLAB and Simulink from any standard web browser wherever you have internet access – just sign in. It is ideal for teaching, learning and convenient, lightweight access.
Online MATLAB/Octave Compiler (GNU Octave, v4. 2.1) helps you to Edit, Run and Share your Octave Code directly from your browser. This development environment provides you version GNU Octave, v4. 2.1.
No, Matlab is not a "compiler", but an "interpreter". A compiler converts the source code to an executable file, which is not readable by human anymore.
Re: 1 - There is the excellent Matlab Documentation, including video tutorials, which will help you understand Matlab. This is much more useful than a compiler, since you'll learn what the code intended, so that you can re-write it in a fashion that is appropriate for C#, rather than trying to copy Matlab-optimized syntax.
However, to test-run Matlab code, there is Octave which provides most of the functionality of core Matlab, but may not support toolbox functions (additional modules of Matlab that you pay for extra).
Re: 2 - Here's what the code does
Instantiate a structure array someVar
(Matlab doesn't need declaring variables beforehand) with a field member
; assign it to myValue1
someVar.member1=myValue1;
Create an additional field member2
, set it to myValue2
someVar.member2=myValue2;
If the condition is true, loop myTotal
times, and set the field member3
of all i
elements of someVar
to myValue3
. Thus, someVar
goes from a 1-by-1 structure array to a 1-by-myTotal
structure array. someVar(1).member1
remains myValue1
, while someVar(i).member1
are initialized to empty ([]
).
if (myCondition)
for i=1:myTotal
someVar(i).member3=myValue3;
end;
end;
/aside: This loop is a rather inefficient way to define the structure. So there may not be much Matlab-optimized syntax in the code you need to translate.
I've written a free online interface for MATLAB/Octave that runs scripts and also has a live prompt where you can type commands. You can also save your scripts between sessions. Check it out at octave-online.net.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With