How to assign x number of variables in a loop...
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!