How iterate inside a excel file and every 21 rows store values in a matrix?
    4 次查看(过去 30 天)
  
       显示 更早的评论
    
I have a attached excel file, and I need to store values in col B and C for each 21 rows in different matrix. I am wondering how can I iterate through excel file and also have a loop to do this. 
What I already have, it is pushing the first 21 rows for col B and C inside the ED_X and ED_Y, and the next 21 rows inside the ES_X and ES_Y. How can I do this through all the excel file?
The excel file is very large file. It does have 425272 rows. I just attached a sample of small file.
sheet1 = 'VolumeTracings';
xlRange1 = 'A2:H425272';
[XY,fileName] = xlsread('VolumeTracings.csv',sheet1,xlRange1);
Label_XY(:,1) = XY(:,1); %x1
Label_XY(:,2) = XY(:,2); %y1
ED_X =  Label_XY(1:21,1)
ED_Y =  Label_XY(1:21,2)
ES_X =  Label_XY(22:42,1)
ES_Y =  Label_XY(22:42,2)
0 个评论
采纳的回答
  Takumi
      
 2020-6-4
        
      编辑:Takumi
      
 2020-6-4
  
      How about saving to a cell array?
sheet1 = 'VolumeTracings - Copy';
[XY,fileName] = xlsread('VolumeTracings - Copy.csv',sheet1);
% Label_XY(:,1) = XY(:,1); %x1
% Label_XY(:,2) = XY(:,2); %y1
Label_X = reshape(XY(:,1),21,[]);
Label_Y = reshape(XY(:,2),21,[]);
nmax = size(Label_X,2);
EX = cell(1,nmax); EY = EX;
for n=1:nmax
    EX{n} = Label_X(:,n);
    EY{n} = Label_Y(:,n);
end
3 个评论
  Takumi
      
 2020-6-4
				sheet1 = 'VolumeTracings - Copy';
[XY,fileName] = xlsread('VolumeTracings - Copy.csv',sheet1);
X1 = reshape(XY(:,1),21,[]);
Y1 = reshape(XY(:,2),21,[]);
X2 = reshape(XY(:,3),21,[]);
Y2 = reshape(XY(:,4),21,[]);
nmax = size(X1,2);
EX = cell(1,nmax); EY = EX;
for n=1:nmax
    EX{n} = [X1(:,n);X2(:,n)];
    EY{n} = [Y1(:,n);Y2(:,n)];
end
更多回答(1 个)
  David Hill
      
      
 2020-6-4
        I don't understand your question completely, but, I would put them all in a single matrix.
XY=reshape(XY(1:42,1:2),21,[]);
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


