Write data on to Excel

조회 수: 1 (최근 30일)
Avishka G
Avishka G 2020년 4월 3일
댓글: Guillaume 2020년 4월 7일
I want to write the following data onto excel, in a way which the first answer (M(: , : , 1)) will be at the range E to G and the next answer (M(: , : , 2)) will be at the range I to K, so 4 column space between each.The sample data is below, is there a easier to do this as sometimes there might be more than 6 data sets.
X = ones(6).*(1:6);
Y = 2*ones(6).*(1:6);
Z = 3*ones(6).*(1:6);
M = permute(cat(3,X,Y,Z), [1 3 2]);
M= reshape(M, 6, []);
  댓글 수: 5
Image Analyst
Image Analyst 2020년 4월 3일
What code? Easier way to do what? I see no code calling xlswrite() or writematrix(). Do you have any code that actually tries to write to Excel?
Avishka G
Avishka G 2020년 4월 6일
I used xls write but i can only copy all the data in M into sheet without keeping space between the 3 columns.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2020년 4월 6일
If I understood correctly:
xlswrite(somefile, reshape([M, nan(size(M, 1), 1, size(M, 3))], 6, []), '', 'E1')
basically pad your 3D matrix with a column of NaNs. NaNs result in empty cells in the output spreadsheet.
  댓글 수: 9
Avishka G
Avishka G 2020년 4월 7일
I used this code but still dont get the answer i want;
L=[0,70,100,150,200].';
N=reshape([L, nan(size(L,1),1,size(L,3))], 1, [])
Guillaume
Guillaume 2020년 4월 7일
That's a different arrangement than in your initial question where each row of the input ended up on a different row of excel whereas you want it all in one row.
L = [0, 70, 100, 150, 200];
N = reshape([L; nan(4, size(L, 2))], 1, [])
This time, we're putting the nans below L and reshaping into a vector.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

제품


릴리스

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by