Save as Excel sheet a matlab variable which contains many other variables and cell arrays
3 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
KSSV
on 24 May 2018
Edited: KSSV
on 24 May 2018
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 Comments
More Answers (0)
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!