marge cells in excel file

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)

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

thank you
its work very well
but if i need to save file as celles below without convert into number.
N =
8×1 cell array
{'12345678910' }
{'234567891011' }
{'3456789101112' }
{'45678910111213' }
{'567891011121314' }
{'6789101112131415' }
{'78910111213141516' }
{'891011121314151617'}
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'.

Sign in to comment.

Asked:

on 4 Apr 2021

Commented:

DGM
on 5 Apr 2021

Community Treasure Hunt

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

Start Hunting!