How iterate inside a excel file and every 21 rows store values in a matrix?

3 ビュー (過去 30 日間)
Neda
Neda 2020 年 6 月 4 日
コメント済み: Neda 2020 年 6 月 5 日
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)

採用された回答

Takumi
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
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
Neda
Neda 2020 年 6 月 5 日
Thanks a lot

サインインしてコメントする。

その他の回答 (1 件)

David Hill
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,[]);

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by