0

I'm got a script that produce a column of 36 values. I would save these 36 values in rows in Excel.

At the moment, I have to run the script each time so I can change the xlrange value, eg: A1 to A1000.

I tried looping the script, and tried to write the values into a new column of a new variable, say mm.

For i=1:1000
Scriptnamehere
mm(i,:)=m or mm(:,i)

Write in excel script here
End

It failed to recognize i for mm.

Mailerdaimon
  • 6,003
  • 3
  • 35
  • 46

2 Answers2

1

You have to preallocate the Matrix mm:

N = 1000; % number of iterations
num_rows = 36; % number of values in every iteration
mm = zeros(num_rows, N); % preallocation
for k = 1:N % don't use i as index variable
    % call script with k, receive m
    mm(:, k) = m;
end
Deve
  • 4,528
  • 2
  • 24
  • 27
  • There are nothing wrong using `i` as index variable, these days. The proper anotation of the complex number i is `1i`. It should be a lot of discussion about this. – patrik Apr 08 '14 at 11:16
  • @patrik `3+5*i` is still valid notation for complex numbers and can therefore break your code. For discussion see http://stackoverflow.com/questions/14790740/using-i-and-j-as-variables-in-matlab/14790765#14790765 – Deve Apr 08 '14 at 11:19
  • That is true, but it is good practice always using `1i` or `1j` and not using `i` or `j` as complex numbers. So to say, if you always use `1i` or `1j` (which matlab warns about otherwise) it should not be any trouble. – patrik Apr 08 '14 at 11:41
1

Maybe use simple assignemt mm = m (I suppose m is the value You got from the script), in You case You tried to assign 36 values to for example mm(1), which would not work. On the other hand I would not recomend to use i as variable for the looping, because it is already predefined by Matlab as imaginary number

For i=1:1000
    Scriptnamehere
    mm = m

    Write in excel script here
End
pezetem
  • 2,503
  • 2
  • 20
  • 38