Convert Char to Cell
Afficher commentaires plus anciens
I am trying to convert this column of characters:
'D48-J06-W470'
into a cell so I can append to a matrix.
I have used str2double but I keep getting errors.
I have searched online but nothing useful arose.
Réponse acceptée
Plus de réponses (3)
Azzi Abdelmalek
le 3 Jan 2014
s='D48-J06-W470'
cellstr(s)
14 commentaires
T
le 3 Jan 2014
Azzi Abdelmalek
le 3 Jan 2014
I think this error does not concerns what I posted. Can you clarify?
T
le 3 Jan 2014
Azzi Abdelmalek
le 3 Jan 2014
A={'D48-J06-W470'
'D48-J06-W470'
'D48-J06-W470'
'D48-J06-W470'}
B=[NaN; NaN ]
out=[A;num2cell(B)]
T
le 3 Jan 2014
Azzi Abdelmalek
le 3 Jan 2014
Modifié(e) : Azzi Abdelmalek
le 3 Jan 2014
T your question is not asked correctly, post clearly what you have, then what you want to get.You don't need to post all your data, just a short example
T
le 3 Jan 2014
Azzi Abdelmalek
le 3 Jan 2014
If you want to append char and double, just use cell array, you can't convert char to double, but you can convert char to cell with cellstr and double to cell with num2cell
Azzi Abdelmalek
le 3 Jan 2014
Until now, I don't know what is your problem? Initially what do you have? and what do you want to obtaint?
Azzi Abdelmalek
le 7 Jan 2014
But the size of the third column should match the size of the list, where do you want to put this third column?
T
le 8 Jan 2014
Andres Parra
le 19 Sep 2018
Saved my day!
Wayne King
le 3 Jan 2014
Modifié(e) : Wayne King
le 3 Jan 2014
Can you be more specific, the below converts it to a cell array:
S = 'D48-J06-W470';
S = {S};
How are you using the term "cell" here?
8 commentaires
T
le 3 Jan 2014
Azzi Abdelmalek
le 3 Jan 2014
How this matrix is double?
T
le 3 Jan 2014
Image Analyst
le 3 Jan 2014
Modifié(e) : Image Analyst
le 3 Jan 2014
This "vector" looks like it already IS a cell array. How did you get it? Did you get it from calling xlsread(), which is one way I know where you will get strings and NaNs in the same array? Do you simply want to delete the NaN cells?
T
le 3 Jan 2014
Image Analyst
le 3 Jan 2014
Modifié(e) : Image Analyst
le 3 Jan 2014
How was Table original gotten, before that line? "Retrieved from some file" is not exactly crystal clear, don't you agree? And the Crystal Ball Toolbox is still under development.
Plus, it looks like Table is already a cell, so what do you mean that you want to convert Table "into a cell so I can append to a matrix." Table is already a cell array, and one column of Table is also a cell array, a column vector where each element is a cell. Do you mean that you all 11 cells in the third column to be stuffed into one single cell instead of being in 11 separate cells? I'm not really sure you know what cells are. A cell is like a bucket, or a container. Have you ever read the FAQ? http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F like I recommended in my answer which you ignored?
T
le 7 Jan 2014
Image Analyst
le 3 Jan 2014
Try this to concatenate cells to make a cell array:
% Create 3 sample strings (character arrays).
string1 = 'D48-J06-W470'
string2 = 'D50-J07-IA2'
string3 = 'abcdef-123456789'
% Make the first cell:
ca = {string1};
% Append strings 2 and 3 into additional cells
% so that we will have a cell array.
% We can use either of 2 different methods (or more).
ca{2} = string2; % Method #1
ca(3) = {string3}; % Method #2
% You can do it via either method.
% Display the cell array.
celldisp(ca);
Be sure to check out the FAQ http://matlab.wikia.com/wiki/FAQ#What_is_a_cell_array.3F for a good explanation of what they are, how they work, and how to use them.
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!