Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can someone either point me to an online/free MATLAB compiler/interpreter or explain what happens in this MATLAB code?

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)

  1. Is there a free online/desktop MATLAB compiler/interpreter somewhere that I can use to test out MATLAB code?

    ...or...

  2. 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?

like image 306
Mike Webb Avatar asked Dec 18 '12 16:12

Mike Webb


People also ask

Can I run MATLAB code online for free?

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.

Is there any online compiler for MATLAB?

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.

Does MATLAB have an interpreter or a compiler?

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.


2 Answers

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.

like image 56
Jonas Avatar answered Sep 17 '22 18:09

Jonas


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.

like image 44
sffc Avatar answered Sep 19 '22 18:09

sffc