Convert Char to Cell
古いコメントを表示
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.
採用された回答
その他の回答 (3 件)
Azzi Abdelmalek
2014 年 1 月 3 日
s='D48-J06-W470'
cellstr(s)
14 件のコメント
T
2014 年 1 月 3 日
Azzi Abdelmalek
2014 年 1 月 3 日
I think this error does not concerns what I posted. Can you clarify?
T
2014 年 1 月 3 日
Azzi Abdelmalek
2014 年 1 月 3 日
A={'D48-J06-W470'
'D48-J06-W470'
'D48-J06-W470'
'D48-J06-W470'}
B=[NaN; NaN ]
out=[A;num2cell(B)]
T
2014 年 1 月 3 日
Azzi Abdelmalek
2014 年 1 月 3 日
編集済み: Azzi Abdelmalek
2014 年 1 月 3 日
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
2014 年 1 月 3 日
Azzi Abdelmalek
2014 年 1 月 3 日
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
2014 年 1 月 3 日
Until now, I don't know what is your problem? Initially what do you have? and what do you want to obtaint?
Azzi Abdelmalek
2014 年 1 月 7 日
But the size of the third column should match the size of the list, where do you want to put this third column?
T
2014 年 1 月 8 日
Andres Parra
2018 年 9 月 19 日
Saved my day!
Wayne King
2014 年 1 月 3 日
編集済み: Wayne King
2014 年 1 月 3 日
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 件のコメント
T
2014 年 1 月 3 日
Azzi Abdelmalek
2014 年 1 月 3 日
How this matrix is double?
T
2014 年 1 月 3 日
Image Analyst
2014 年 1 月 3 日
編集済み: Image Analyst
2014 年 1 月 3 日
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
2014 年 1 月 3 日
Image Analyst
2014 年 1 月 3 日
編集済み: Image Analyst
2014 年 1 月 3 日
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
2014 年 1 月 7 日
Image Analyst
2014 年 1 月 3 日
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.
カテゴリ
ヘルプ センター および File Exchange で Data Type Conversion についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!