フィルターのクリア

Error in converting Cell array to double

4 ビュー (過去 30 日間)
Mo Ba
Mo Ba 2017 年 6 月 27 日
コメント済み: Stephen23 2017 年 6 月 28 日
Hi,
I'm converting some cell arrays to their equivalent numbers, but have an error for couple of them. I attached the variables to this question.
The problem is in my cell array some elements are 'NaN' and also some other elements have different length.So when I'm using this command to convert:
G8_D=str2num(cell2mat(G8));
C1_D=str2num(cell2mat(C1));
I get this error:
Dimensions of matrices being concatenated are not consistent.
The important matter is 'I can not remove Nan elements and shift all cells up or down because the location of each element is meaningful for me, but that's ok if I get a number like 0 instead of Nan '
I was thinking to maybe add some zeros to the end of elements to make their length equal but couldn't get a good result.
Any idea to how to convert these two cell arrays to number?
Thanks
  1 件のコメント
Stephen23
Stephen23 2017 年 6 月 28 日
There are no NaN strings in those cell arrays:
>> find(strcmpi(C1,'NaN'))
ans =
Empty matrix: 0-by-1
>> find(strcmpi(G8,'NaN'))
ans =
Empty matrix: 0-by-1

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

採用された回答

Stephen23
Stephen23 2017 年 6 月 28 日
str2double converts those cell arrays of strings to double:
>> str2double(C1)
ans =
0.23
0.23
0.23
0.23
0.23
0.24
0.23
0.23
0.23
0.24
0.24
0.24
0.24
0.24
0.23
999
0.24
...
0.23
0.24
0.23
0.23

その他の回答 (0 件)

カテゴリ

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