I need to save in Matlab some matrices created at each iteration of a loop using names depending on the loop index h
. More precisely, the code is
for h=1:4
A=randn(2,1);
B=randn(2,1);
C=randn(2,1);
save(sprintf('data%d.mat',h),'-v7.3', 'A' , 'B', 'C')
end
for h=3
,
I get the matrix data3
, whose name depends on the loop index, containing the matrices A,B,C
. I want to modify that line of code in a way such that data3
containes A3,B3,C3
.
Note: using save(sprintf('data%d.mat',h), ['A' h], ['B' h], ['C' h] ,'-v7.3')
gives the error
Error using save
'A' is not a valid variable name.
See Question&Answers more detail:os