Matlab file saving.

  • MATLAB
  • Thread starter PhilippH
  • Start date
12
0

Main Question or Discussion Point

Hi I have a question, I have to save to file the matrixs generated by an algoritm in Matlab. So i was wondering if is it possibile and how, to use in the filename a variable of the algoritm.

Let's say "i" is the counter of my cicle and i would like to save the matrix generated at every cicle to a file with the name NAMEFILE-i.

i.e.
for i=1:4
a=i;
save file-i a
end

Of course this is not working :-)

Do i need to use a string?
 

Answers and Replies

141
0
you need to use the function int2str

mystr = int2str(i);

alternatively if you want to make the file name "NAMEFILE-i" then you can use

sprintf(mystr,'NAMEFILE-%i',i);

you'll have to check the syntax of this though, i can't remember it exactly off-hand. note that %i in the second argument refers to an integer type, not the variable i, whereas i in the last argument is the variable i.
 
141
0
By the way to output matrices to file...

outfile = fopen(int2str(i),'w');
dummy = fwrite(outfile,M,'float64');
fclose(outfile);

This saves the matrix M as binary data to the file 'i'
 
12
0
Ah thx that was what I was looking for. Now I just need to fix how to save in the right format.
 

Related Threads for: Matlab file saving.

Replies
3
Views
22K
  • Last Post
Replies
2
Views
36K
  • Last Post
Replies
7
Views
14K
Replies
0
Views
3K
  • Last Post
Replies
1
Views
1K
  • Last Post
Replies
1
Views
4K
  • Last Post
Replies
1
Views
6K
  • Last Post
Replies
1
Views
1K
Top