marge cells in excel file
Show older comments
hello everyone
i have excel file and want to marge each celles
examples
A1 to I1 and marge value in cell k. image below ulistarate what i want.

Answers (1)
DGM
on 5 Apr 2021
Well let's start with this:

[N T R]=xlsread('testspreasheet.xls');
N=num2str(N);
N=mat2cell(N,ones(1,size(N,1)),size(N,2));
N=strrep(N,' ','')
at this point N is a cell array of strings:
N =
8×1 cell array
{'12345678910' }
{'234567891011' }
{'3456789101112' }
{'45678910111213' }
{'567891011121314' }
{'6789101112131415' }
{'78910111213141516' }
{'891011121314151617'}
You can try to convert it to numbers and write it to a file
longestline=max(cellfun(@numel,N));
N=cellfun(@str2double,N)
dlmwrite('output.csv',N,'delimiter',',','precision',longestline);
but you might find out that it's easy to run out of precision.
If you'd rather write the strings, I'm not sure of an elegant way that doesn't involve building the file line by line.
2 Comments
dhafar hamed
on 5 Apr 2021
DGM
on 5 Apr 2021
If you need a text or delimited text file:
If you just want to save it as a cell array in a .mat file, you can just use 'save'.
Categories
Find more on Spreadsheets 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!