How iterate inside a excel file and every 21 rows store values in a matrix?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Takumi
am 4 Jun. 2020
Bearbeitet: Takumi
am 4 Jun. 2020
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 Kommentare
Takumi
am 4 Jun. 2020
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
Weitere Antworten (1)
David Hill
am 4 Jun. 2020
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 Kommentare
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!