How to DEconcatenate a string in matlab?

Hello!
How to deconcatenate a string in matlab? I read some data (Names) from excel, and sort them in a matrix. Then the I use the stored data and concatenate them with an existing string, after that I write the new string in excel, but the data (Names) are concatenated and my code put everithing in one cell.
How to say to Matlab not to concatenate my string???

2 Comments

can you upload your code ? and an example of filenames?
Use cell arrays of character vectors when you xlswrite() instead of char arrays.

Sign in to comment.

 Accepted Answer

for i=end_ln:length(raw(:,1));
.
.
.
if raw{i,1} == 1 && isnan(raw{i,1})~=1 && isempty(raw{i,1})~=1;
[NameX(i,1)] =(raw(i,3)); % where raw(i,3) is the column C from the xls file, conteins the names
end
end
c = [NameX{:}] % and here it puts all the names as a concatenated text

5 Comments

[NameX{:}]
means the same thing as
horzcat(NameX{:})
which is
horzcat(NameX{1},NameX{2}, NameX{3}, ... NameX{end})
which is going to put everything together into one character vector.
If you are just trying to convert from a column oriented cell array of character vectors into a row oriented cell array of character vectors, that would just be c = NameX.';
You should not xlswrite() individual character vectors: you should xlswrite a cell array, some entries of which might be character vectors. For example you could just xlswrite() NameX to get the names as separate excel cells down a column.
Walter Roberson, thank you very much. It works great! :)))) Thank you!
John Rebbner
John Rebbner on 18 Jan 2019
Edited: Stephen23 on 18 Jan 2019
I have another problem. This works perfectly, but only in case of writing in xls file. I want to write the same values by using fprintf fun but in .dat file. Does fprint fun can write a cell array in a file????
no fprintf cannot write cell arrays. you would use cell expansion . For example
fprintf(fid, '%s\n', Cell_array_of_labels{:});
"Does fprint fun can write a cell array in a file????"
No, but you can use a comma-separated list to provide multiple input arguments:

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!