how I can automatically save the output of a for loop?
Mostra commenti meno recenti
I created a loop that performs operations on a series of 2D matrices, each cycle I want to save the output matrix, so I need a way to automatically save these matrices creating an automatic generation of file names
3 Commenti
Anand
il 8 Mar 2015
Store each matrix in an array
Ex
for k=1:1:(no of matrices)
A{k}=result
end
you can view any result by A{1}, A{2}...
Francesca Di Nicola
il 8 Mar 2015
Francesca Di Nicola
il 8 Mar 2015
Risposte (1)
Star Strider
il 8 Mar 2015
Modificato: Star Strider
il 8 Mar 2015
0 voti
If you’re creating a series of 2D matrices, I would concatenate them into a single resultant 3D matrix (use something like: Savemat=cat(3, Savemat, Mat); then save the updated ‘Savemat’ in the same .mat file at each iteration, or preferably after the loop.
That way, you have all your 2D matrices in one 3D matrix that you can load from one file and easily address in your code.
6 Commenti
Francesca Di Nicola
il 8 Mar 2015
Star Strider
il 8 Mar 2015
To use a particular page (third dimension) of a 3D matrix, you have to address it specifically:
M = Savemat(:,:,5);
This creates ‘M’ as the 5th page — corresponding to the 5th iteration of your loop — to use in any calculations that require a 2D matrix. It would be easier than using a cell array, because there would be no need to convert from a cell array to a double array.
Francesca Di Nicola
il 8 Mar 2015
Star Strider
il 8 Mar 2015
I thought from your Question that you had 2D matrices that you want to save. How do you intend to multiply your 3D matrices? What result do you want to get? I don’t understand what you’re doing.
Francesca Di Nicola
il 8 Mar 2015
Modificato: Francesca Di Nicola
il 8 Mar 2015
Star Strider
il 8 Mar 2015
This seems quite distant from your original Question here.
Create a new Question that describes in some detail what you really want to do, expanding on your last Comment. It seems like a much more complicated project than I want to deal with.
Write the code to implement it yourself. If you have problems with your code, post the relevant parts of it along with a description of what you want your code to do and what it is doing, including the entire red text of any error messages that your code throws.
We will then help you get it to run.
I will delete my Answer — including this Comment — in a few hours, since it does not address your actual problem.
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!