Problem in convert cell to string.

I have a cell show like this
% code
val =
title="
google
">
The value is 3*7 char. If I want to convert into string to be ---> title="google"> What can I do? I have found many solution but can't help for this one. Thank you.

 Risposta accettata

Possibly, this is what you want:
strjoin(cellstr(val), '')

5 Commenti

Ara
Ara il 7 Gen 2015
It's error --> Error using strjoin (line 52) First input must be a 1xN cell array of strings.
Is it because my cell has 3x7 char right? how to do it?
Anyway thank you for your answer.
Guillaume
Guillaume il 7 Gen 2015
Modificato: Guillaume il 7 Gen 2015
It's not clear what the type of val is because of your use of the word cell which has a specific meaning in matlab. Is it a 3x1 cell array or a 3x7 char array (or something else)?
To know for sure, tell us the output of
whos val
Ara
Ara il 7 Gen 2015
It is 3x7 char.
In that case, my code works:
>> val = ['title="'
'google '
'"> '];
>> whos val
Name Size Bytes Class Attributes
val 3x7 42 char
>> strjoin(cellstr(val), '')
ans =
title="google">
Ara
Ara il 7 Gen 2015
Thank you. It's work

Accedi per commentare.

Più risposte (1)

S = reshape(A',1,[])
No reason to convert to and from a cell.

3 Commenti

Yes, there is, the extra spaces that cellstr trims. Your solution has an extra space after 'google' and a bunch of them after the closing '>'.
Sean de Wolski
Sean de Wolski il 7 Gen 2015
Modificato: Sean de Wolski il 7 Gen 2015
Ahh, I didn't realize cellstr implicitly calls deblank. Good to know!
Ara
Ara il 7 Gen 2015
Thank you very much.

Accedi per commentare.

Categorie

Richiesto:

Ara
il 7 Gen 2015

Commentato:

Ara
il 7 Gen 2015

Community Treasure Hunt

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

Start Hunting!

Translated by