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!