read csv file in sequence and post process data
    4 views (last 30 days)
  
       Show older comments
    
Hello all,
I have written a code manually to extract information regarding 5 matrices and postporcess the data (I want to get the maximun value of the column 11, . Each matrix has a different size (12 columns x around 300 rows).
The example of this code is:
T1 =csvread('contour_oh01_pe100.1.csv',1,0);
 T2 =csvread('contour_oh01_pe100.2.csv',1,0);
 T3 =csvread('contour_oh01_pe100.3.csv',1,0);
 T4 =csvread('contour_oh01_pe100.4.csv',1,0);
 T5 =csvread('contour_oh01_pe100.5.csv',1,0);
[M1,I1] = max(T1(:,11))
row1=T1(I1,:);
[M2,I2] = max(T2(:,11))
row2=T2(I2,:);
[M3,I3] = max(T3(:,11))
row3=T3(I3,:);
[M4,I4] = max(T4(:,11))
row4=T4(I4,:);
[M5,I5] = max(T5(:,11))
row5=T5(I5,:);
I am try to do it using a for-loop. But I am having problems to store the T1,T2,T3, T4 and T5:
for i=1:5
T(i)=[T,'num2str(n)']
[M(i),I(i)]=max(T(i)(:,11))
end
I hope that you may help me.
0 Comments
Accepted Answer
  madhan ravi
      
      
 on 15 Feb 2019
        Use cell arrays instead of numbering variables ( https://www.mathworks.com/matlabcentral/answers/105936-how-to-make-dynamic-variable-names-a1-a2-an-with-for-loop-using-eval-num2str ):
T=cell(1,5); % preallocate
row=cell(1,5);
M=cell(1,5);
I=cell(1,5);
for k=1:5
T{k}=csvread(sprintf('contour_oh01_pe100.%d.csv',k),1,0);
[M{k},I{k}] = max(T{k}(:,11));
row{k}=T{k}(I{k},:);
end
0 Comments
More Answers (1)
See Also
Categories
				Find more on Shifting and Sorting Matrices 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!