how to feed one string to array on NaN?
9 ビュー (過去 30 日間)
古いコメントを表示
Abdulaziz Abutunis
2017 年 1 月 19 日
回答済み: Abdulaziz Abutunis
2017 年 1 月 19 日
Dear MATLABERs :)
Is it possible to add a string to an array of NaN The next example does not work N = NaN(10,1); N(5,1)='Stop'; the result should be a column of NaN but the fifth element is Stop.
Thanks Aziz
0 件のコメント
採用された回答
Walter Roberson
2017 年 1 月 19 日
No. NaN is numeric, but 'Stop' is a character string. It is not possible to have numbers and characters in the same array.
You could use one of the following:
%cell array of mostly numeric
N = num2cell( NaN(10,1) );
N{5} = 'Stop';
or
%cell array of char vectors
N = cellstr( num2str( NaN(10,1) ) );
N{5} = 'Stop';
or, if you have R2016b or later,
%array of string data type
N = string(num2str(NaN(10,1)));
N(5) = 'Stop';
0 件のコメント
その他の回答 (2 件)
James Tursa
2017 年 1 月 19 日
No, you can't combine character strings as elements of a numeric array like that. To combine different data types in one variable, consider using a cell array.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!