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
someVarinto an array? Do I losemember1andmember2or does it save what I have set somehow?
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 fieldmember; assign it tomyValue1Create an additional field
member2, set it tomyValue2If the condition is true, loop
myTotaltimes, and set the fieldmember3of allielements ofsomeVartomyValue3. Thus,someVargoes from a 1-by-1 structure array to a 1-by-myTotalstructure array.someVar(1).member1remainsmyValue1, whilesomeVar(i).member1are initialized to empty ([])./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.