Save into cell or ND array
이전 댓글 표시
Hello Matlabers
I have the following code.
m = 2;
n = 3;
r = 5;
V = 2:2:20;
for ii = 1:5
W = rand(m,r);
H = rand(r,n);
S = struct();
for jj = 1:numel(V)
S(jj).W0 = rand(m,V(jj));
S(jj).H0 = rand(V(jj),n);
S(jj).rank = V(jj);
end
F = fullfile('DATA',sprintf('data_%d.mat',ii));
save(F,'W','H','S')
end
The above code saves the files as
Data1.mat
W, H and S % where S is a structure containing all values of the inner loop W0, H0
Data2.mat
W, H and S
.
.
Data5.mat
W, H and S
I dont want W0 and H0 to be in a struct. I want them to be saved individually like W and H because I will be using them as input to a function later. So ideally this is how i want to save it
% if i open the matfile i want to see the individual variables.
% and not being group into 1 struct. I want control over each of them.
Data1.mat
W,H
W0_2, W0_4, W0_6, ..., W0_20
Data_2.mat
W,H
W0_2, W0_4, W0_6, ..., W0_20
.
.
Data_5.mat
W,H
W0_2,W0_4,W0_6,...,W0_20
Thanks
댓글 수: 2
Original question and answer:
@fadams18: you have copied my code, so please accept my answer. Accepting answers is how you can show your appreciation for the volunteers who help you.
fadams18
2019년 1월 10일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!