How to assign x number of variables in a loop...
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to write a function for a program that extracts information from .dat files and puts it into excel. Each .dat file has multiple sets of information that are all different sized matrices.
The problem is that each file can have varying number of these tests. I want to be able to input the number of tests that are in a series of .dat files and have the loop compensate for it. There are hundreds of .dat files for each setup that might have 8 or 12 or more tests each.
Here’s what I have now:
R1=zeros(m(1),n(1)); legend1=cell(1,n(1));
for k = 1:m(1)
for i = 1:n(1)
r1(k,i)=str2double(C(k+i-1+(k-1)*(n(1)-1)+s(1)));
legend1(i)=C(s(1)-n(1)+i);
end
end
r2=zeros(m(2),n(2)); legend2=cell(1,n(2));
for k = 1:m(2)
for i = 1:n(2)
r2(k,i)=str2double(C(k+i-1+(k-1)*(n(2)-1)+s(2)));
legend2(i)=(C(s(2)-n(2)+i));
end
end
…
R12=zeros(...
…
etc...
Here’s what I’d like to do:
user_input=12; % 12 tests for this run
for j=1:user_input
C=sprintf('A%d', j);
L=sprintf('Legend%d',j);
end
for j = 1:length(C)
for k = 1:m(1)
for i = 1:n(1)
C(j)(k,i)=str2double(C(k+i-1+(k-1)*(n(j)-1)+s(j)));
L(j)(i)=C(s(1)-n(j)+i);
end
end
end
Obviously that doesn’t work, but is there another way?
댓글 수: 0
답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!