How can I use 'strcat' and 'for loop' to read my Excel data?
Show older comments
Hello, my Excel data name is "b1,b2...b40", and i want to write a code with for loop to read Excel.
for example:
b1 = xlsread('b1.csv'); %read my Excel data [2048*2]
r1 = [b1(:,2)./cal(:,2)]; %calculate my data
b1(:,2) = r1; %cover my original data
%%%%%%%%%%%%%%%%%%%%%%%%%%
I want to use "for loop" to run all my data (40), but it didn't work.
this is my code:
for i=1:40
strcat('b',num2str(i)) = xlsread(strcat('b',num2str(i),'.csv'));
strcat('r',num2str(i))= [strcat('b',num2str(i),'(:,2)') ./ cal(:,2)];
strcat('b',num2str(i),'(:,2)') =strcat('r',num2str(i));
end
Matlab usually said"Subscripted assignment dimension mismatch.", but I don't know how to fix it.
Plz help me, or recommend me, thank you everyone.
1 Comment
Do NOT dynamically name variables! Dynamically naming variables is one way that beginners force themselves into writing slow, complex, buggy code that is hard to debug. Read this to know why:
Much simpler and more efficient is to use indexing, exactly as the MATLAB documentation shows:
Please upload a sample data file by clicking the paperclip button.
Accepted Answer
More Answers (0)
Categories
Find more on Data Import from MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!