Function Save() and optimizzation

2 次查看(过去 30 天)
Salvatore Turino
Salvatore Turino 2011-11-18
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 个评论
Swarooph
Swarooph 2011-11-18
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 2011-11-19
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

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2011-11-18
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 个评论
Salvatore Turino
Salvatore Turino 2011-11-19
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.....

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by