Convert Char to Cell
443 views (last 30 days)
Show older comments
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.
0 Comments
Accepted Answer
Simon
on 8 Jan 2014
Hi!
It seems you want to do:
ListCell = num2cell(List);
NewCol = size(List, 2) + 1;
for n = 1:size(Table, 1)
tf = (List(:, 1) == Table{n, 1});
ListCell(tf, NewCol) = Table(n, 3);
end
More Answers (3)
Wayne King
on 3 Jan 2014
Edited: Wayne King
on 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 Comments
Image Analyst
on 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.
0 Comments
See Also
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!