Save as Excel sheet a matlab variable which contains many other variables and cell arrays

3 次查看(过去 30 天)
Hi Everyone,
I have a problem as to how I may save a cell array which is contained inside a variable as an excel sheet. I have attached a screen shot. The "ma" is the variable, and I would like to save the cell array "msd" as an excel sheet. Would be great if someone could help me with this, as it is quite complicated for me as this case is a cell array inside another variable... I am looking at both options where I save the cell array as an excel sheet with several tabs (each tab containing each cell data) and the other situation where the excel sheet will have only one sheet, where the cell information will be stored as consecutive sets of columns, one after the other. I don't really know if this is possible...? (Matlab version R2015a)
Thank you in advance!
Best Sara

采纳的回答

KSSV
KSSV 2018-5-24
编辑:KSSV 2018-5-24
Writes one matrix/ cell in different sheets:
N = 5 ;
A = cell(N,1) ;
for i = 1:N
A{i} = rand(2,3) ;
end
for i = 1:N
xlswrite('check.xlsx',A{i},i)
end
Writes matrix into one sheet, with space between each cell.
N = 5 ;
A = cell(N,1) ;
for i = 1:N
A{i} = rand(2,3) ;
end
B = A ;
[m,n] = size(A{1}) ;
A = cell2mat(A) ;
pos = m+1:m+1:m+(N+1)*m ;
[r,c] = size(A);
add = numel(pos); % How much longer Anew is
Anew = NaN(r + add,c); % Preallocate
idx = setdiff(1:r+add,pos); % all positions of Anew except pos
Anew(idx,:) = A;
xlswrite('check.xlsx',Anew)
  5 个评论
SNT
SNT 2018-5-31
Hi KSSV,
When I tried the second approach, of saving I get an error at this line. Have I made an error?
Anew(idx,:) = A;
Subscripted assignment dimension mismatch.
Thanks a lot! Sara
SNT
SNT 2018-5-31
This is the whole code I put on matlab
N=100;
[m,n] = size(ma.msd {1}) ;
A = cell2mat(ma.msd) ;
pos = m+1:m+1:m+(N+1)*m ;
[r,c] = size(ma.msd);
add = numel(pos); % How much longer Anew is
Anew = NaN(r + add,c); % Preallocate
idx = setdiff(1:r+add,pos); % all positions of Anew except pos
Anew(idx,:) = A;
xlswrite('check.xlsx',Anew)
Thanks!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by