How to merge words in the cells to form a string
13 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi
I stuck into a phase of my work where I am looking forward to merge the words staying in the cells to form a string. My scenerio is like following:
A=562833 x 1 cell containing these following cells:
![z1.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237433/z1.jpeg)
As an example,
A{1,1} is of size {2x1 cell} contains words bihdai and majesti
A{2,1} is of size {5x1 cell} contains words model,love,take,time and ur
![z2.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237434/z2.jpeg)
![Z3.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237435/Z3.jpeg)
![Z4.jpg](https://www.mathworks.com/matlabcentral/answers/uploaded_files/237436/Z4.jpeg)
I am looking forward to merge the cells to form a string and final output would be like
A(1)=" bihdai majesti"
A(2)="model love take time ur"
When I am trying with cell2str or string() to solve this, I am getting following error as well:
Conversion from cell failed. Element 1 must be convertible to a string scalar.
I am attaching a samples of the variables
Would you please advise me how to solve this scenerio.
Thanks,
2 Kommentare
Antworten (3)
Bruno Luong
am 8 Sep. 2019
Bearbeitet: Bruno Luong
am 8 Sep. 2019
A={{"happy" "birdday"} {"I" "am" "a" "boy"} {"good" "boy"}};
S = strtrim(string(char(cellfun(@(c) sprintf('%s ',c{:}), A, 'unif', 0))))
2 Kommentare
Bruno Luong
am 8 Sep. 2019
Bearbeitet: Bruno Luong
am 8 Sep. 2019
The screen shot cannot desribe accurately your data structure/class.
Beside I never use the workspace so I don't know how to read it.
madhan ravi
am 8 Sep. 2019
Bearbeitet: madhan ravi
am 8 Sep. 2019
cellfun(@(x) join(string(x)),A).'
2 Kommentare
madhan ravi
am 8 Sep. 2019
Bearbeitet: madhan ravi
am 10 Sep. 2019
>> A={'Will';'you';'make like easier';'by';'clear for Godsake'}
A =
5×1 cell array
{'Will' }
{'you' }
{'make life easier' }
{'by explaining' }
{'clearly for Godsake'}
>> join(string(A))
ans =
"Will you make life easier by explaining clearly for Godsake"
>>
Bruno Luong
am 9 Sep. 2019
Bearbeitet: Bruno Luong
am 9 Sep. 2019
a_=a'; % then copy screen
followed by useless screen capture.
Please do
a__ = a(1:10);
save(' a__.mat','a__');
and attach the file a__.mat here for us to try.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Type Conversion finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!