smilingbuddha
smilingbuddha

Reputation: 14764

Matrix generation with octave in a loop

Hi I want to generate some random matrices of size Nx3 for varying N, in GNU-Octave. I want to save each of these matrices to a different file.

The script below almost does the job, but strangely it produces only file with the name int2str(N) ; it keeps overwriting the files produced at the previous iteration.

for i=1:10
  N=(2**i)
  A=rand(N,3);
  save int2str(N) A
end

The script is interpreting int2str(N) itself as a string. How do I avoid this behaviour?

Upvotes: 1

Views: 414

Answers (1)

jdigital
jdigital

Reputation: 12296

You can invoke save with the function form:

save(int2str(N), "A")

Upvotes: 1

Related Questions