matlab - Storing Results of a Operation in a Matrix -
Let's say I want to take 1 to 100 (in degrees) sin.
From my background, my instinct is for loop 1 to 100 for a loop (some I can do in Matlab) in matrix / vector / array, I will store sin (x) where x The loop is the counter.
I do not understand how to do this in Matlab I am making an array
x = [1 .. 100];
and then do
x [offset] = number here;
I know the "right" way in addition to using + to operate like you + and with a function like sin I'm pretty sure that you just do it
resultArray = sin (x);
I just want to know that I can do in a way that has never come, thus my question is here. :)
As others have already indicated that there are also loops in MATLAB . Support for
You should give everything you need, how it works. The difference from C is that the loop can go to the object and not only an integer:
objects = struct ('name', 'obj1', 'obj2'}, 'field 1' { 'VALUE1', 'value2'});
This example would be output to: x = object Disp (Sprintf ('Object% s field 1 =% d', x.Name, x.Field1)):
< Pre> object obj1 field 1 = value1 object obj2 field1 = value2
it could be
for i = 1: length ( Objects) x = objects (i); Disp (Sprintf ('Object% s field 1 =% d', x.Name, x.Field1))
And now what I really want to say: If you ever Write, stop and think for loop in MATLAB! You can vector the code for most of the tasks so that it can use metrics operation and Biltine functions rather than looping on the data. It usually returns a big speed gain It is not uncommon that vector code code makes 100x faster than looping. In recent versions of MATLAB, JIT compilation which makes less dramatic than before, but still: If you can always make vector.
Comments
Post a Comment