Function Save() and optimizzation

2 views (last 30 days)
Salvatore Turino
Salvatore Turino on 18 Nov 2011
Hello i want to optimize my code. i have these 3 matrix:
save H_scorr
save Hscorr_abs
save Hscorr_ang
in exit from a for() cicle, that are all 7x7. Does exist a way to save them in 1 file .mat? Next step is that these three matrix became 12 (4x3matrix all 7x7) and i need to save all of them. Actually the only idea i had to save them all is a simply:
if i==1
H_scorr=Hscorr;
H_scorr_abs=Hscorr_abs;
H_scorr_ang=Hscorr_ang;
save H_scorr
save Hscorr_abs
save Hscorr_ang
end
with the if that is repeated four times but of course i don't like this way....can you help me to optimize this part of my code?
the idea i've had is:
H_scorr(i)=Hscorr;
but i've got this error:
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> prova at 103 H_scorr(i)=Hscorr;
thank you
  2 Comments
Swarooph
Swarooph on 18 Nov 2011
Let me reiterate the question to see if I understand this correctly.
1. You want to know how to save 3 different variables in a single MAT file
2. Do you want to save all the 12 matrices separately so that finally your MAT file will have 12 matrices?
Salvatore Turino
Salvatore Turino on 19 Nov 2011
1. yes
2. i want to save the 12 matrices separately so that finally i'll have 4 .mat file with 3 matrices inside (like in point 1), without using 4 "if" cases but only, if it is possibile, the indice i of the for() like a vector/matrix

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 18 Nov 2011
It can be quite informative if you look up the help for functions. That way you'd see how what you want is there in black and white as an example:
save(yourFullMatFileName, 'H_scorr',...
'Hscorr_abs', 'Hscorr_ang');
  1 Comment
Salvatore Turino
Salvatore Turino on 19 Nov 2011
Attempt to reference field of non-structure array.
Error in ==> prova at 110
save(Hscorr.mat,'H_scorr','Hscorr_abs', 'Hscorr_ang');
doesn't work.....

Sign in to comment.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!