splitting range of rows in separate column

i have a large excel data. it has two column. i want to splitt every 17 rows in separate column in the same sheet
how can i do it in matlab?

 Akzeptierte Antwort

Chris
Chris am 8 Okt. 2022
Bearbeitet: Chris am 8 Okt. 2022

0 Stimmen

A = readmatrix('filename.xlsx');
len = size(A,1);
% Make sure array length is divisible by 17.
B = padarray(A,[17-mod(len,17), 0],NaN,'post');
% Reshape each column
wid = size(B,1)/17;
C(:,1:3:3*wid) = reshape(B(:,1),17,wid);
C(:,2:3:3*wid+1) = reshape(B(:,2),17,wid);
% Clear out the zeros in between columns
C(:,3:3:end) = nan;
% Write to file
writematrix(C,'newfile.xlsx')
Is this what you mean?

4 Kommentare

NAVEED ULLAH
NAVEED ULLAH am 8 Okt. 2022
yes, thank you for the effort.
one more thing: After every two columns it create one empty column. help regarding removing that empty column will be appreciated
@naveed ullah Oh, I thought that was part of what you wanted. Just change the indexing.
C(:,1:2:2*wid) = reshape(B(:,1),17,wid);
C(:,2:2:2*wid+1) = reshape(B(:,2),17,wid);
% The following line is no longer necessary
% C(:,3:3:end) = nan;
NAVEED ULLAH
NAVEED ULLAH am 8 Okt. 2022
Thank you so much.
Chris
Chris am 8 Okt. 2022
No problem.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Gefragt:

am 8 Okt. 2022

Kommentiert:

am 8 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by