How to output a large matrix to one excel with multiple sheets in specific size?

Hello,
I have a large matrix (289x46) which are x and y data. The first 289x23 are x data, and the rest 289x23 are y data. I want to export each column of x and y from the matrix to one sheet in excel, move to the next column of x and y, output again ans so on. Therefor I can have 23 sheets after output. How can I make this happen?
Thank you.

 Accepted Answer

% a 289x52 matrix:
xy = readmatrix('test100_4.4.22cellsmeetcriteria.xlsx');
% write each pair of columns (one x and one y)
% to a sheet of output.xlsx, for the first 23 pairs:
for ii = 1:23
writematrix([xy(:,ii) xy(:,ii+23)],'output.xlsx','Sheet',ii);
end

4 Comments

Sorry I didn't make it clear in the main post. My x,y data are blended in one matrix. The size is 289x46, first 23 columns (289x23) are x data, and the rest 24-46 columns (289x23) are y data. I want to extract x1,y1 to one sheet, and move to x2,y2 and so on.
I have updated my answer according to your clarification. I found that there were 52 columns in the file, so I just used the first 46.

Sign in to comment.

More Answers (0)

Products

Release

R2021b

Asked:

on 25 Apr 2022

Commented:

on 26 Apr 2022

Community Treasure Hunt

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

Start Hunting!