Convert Char to Cell

431 ビュー (過去 30 日間)
T
T 2014 年 1 月 3 日
コメント済み: Andres Parra 2018 年 9 月 19 日
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.

採用された回答

Simon
Simon 2014 年 1 月 8 日
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
  1 件のコメント
T
T 2014 年 1 月 8 日
編集済み: T 2014 年 1 月 8 日
This works !

サインインしてコメントする。

その他の回答 (3 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 3 日
s='D48-J06-W470'
cellstr(s)
  14 件のコメント
T
T 2014 年 1 月 8 日
List(:,1) is an array of ID's. Table(:,1) are the ID's associated with the actual label. The idea was to assign a label in List as the 8th column.
I have been told that this is not possible because the matrix cannot not take more than one character, is this true? I may have to think of something else.
Andres Parra
Andres Parra 2018 年 9 月 19 日
Saved my day!

サインインしてコメントする。


Wayne King
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
T 2014 年 1 月 7 日
編集済み: T 2014 年 1 月 7 日
The table was retrieved from a MS Access file. That's correct, Table is a cell.
I want to take the third column of Table, and append to a 40 x 4 matrix of type double using the ID in column 1. I have done this part, I just need to deal with the data types. I cannot simply use mat2cell as I get this error:
Warning: Single input behavior is obsolete and will be removed in a future release of MATLAB. Use
C={X} instead.
> In mat2cell at 53
In script>menu_loadFile_Callback at 198
In gui_mainfcn at 96
In script at 42
In @(hObject,eventdata)script('menu_loadFile_Callback',hObject,eventdata,guidata(hObject))
nor can I use {matrix}
T
T 2014 年 1 月 7 日
I tried using:
cellfun(@(c_) c_ - '0', Table(index,3), 'UniformOutput', false);
but
The following error occurred converting from cell to double:
Error using double
Conversion to double from cell is not possible.

サインインしてコメントする。


Image Analyst
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.

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by