i wanted to ask this:
If i have this matrix:
magnetT=NaN(Maxstep,2);
and want to prepend to it the "{0 1}"
how can i write it?
Also,if i have this in mathematica in a loop:
magnetT[[i]] = {T, Apply[Plus, Flatten[mlat]]开发者_开发百科/L2}
the equivalent in matlab isn't this???
magnetT(i,2)=[T ,sum(mlat(:))./L2];
because it gives me :Subscripted assignment dimension mismatch.
Error in ==> metropolis at 128 magnetT(i,2)=[T,sum(mlat(:))./L2];
Thanks
I'll attempt to answer your first question both questions.
You asked about prepending the NaN array to {0,1} which is a cell array. Any data objects can be readily bundled into a cell array:
>> anyData = NaN(3, 2); >> newCellArray = {anyData; {0, 1}} newCellArray = [3x2 double] {1x2 cell }
If you are instead trying to concatenate the results into a numeric matrix, the following will help:
>> Maxstep=3; >> magnetT=NaN(Maxstep,2); >> newArray = [magnetT; 0 1] newArray = NaN NaN NaN NaN NaN NaN 0 1
For your second question, MATLAB is complaining about trying to store a vector in one element of magnetT
. When computing:
magnetT(i,2)=[T ,sum(mlat(:))./L2];
the right-hand side will create a vector while the left-hand side is trying to store that vector where a scalar is expected. I don't know exactly what you're trying to achieve and I'm not very familiar with Mathematica syntax but perhaps you need to do this instead:
magnetT(ii,:) = [T sum(mlat(:))./L2];
or, in other words:
magnetT(ii,1) = T; magnetT(ii,2) = sum(mlat(:)) ./ L2;
精彩评论