Finding values of specific range from table row or column
3 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm having the Table whose first column is as A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502]
I want to select range as 12345 to NaN (shown in bold) , 457 to NaN and so on.
Please guide.
0 件のコメント
採用された回答
Stephen23
2019 年 7 月 26 日
編集済み: Stephen23
2019 年 7 月 26 日
>> A = [12345 NaN NaN NaN NaN 457 NaN NaN NaN 785 NaN NaN NaN NaN NaN NaN 74502].'
A =
12345
NaN
NaN
NaN
NaN
457
NaN
NaN
NaN
785
NaN
NaN
NaN
NaN
NaN
NaN
74502
Method one: accumarray:
>> C = accumarray(cumsum(~isnan(A)),A,[],@(v){v});
>> C{:}
ans =
12345
NaN
NaN
NaN
NaN
ans =
457
NaN
NaN
NaN
ans =
785
NaN
NaN
NaN
NaN
NaN
NaN
ans =
74502
Method two: mat2cell:
>> X = diff(find([true;diff(isnan(A))<0;true]));
>> C = mat2cell(A,X,1);
>> C{:}
ans =
12345
NaN
NaN
NaN
NaN
ans =
457
NaN
NaN
NaN
ans =
785
NaN
NaN
NaN
NaN
NaN
NaN
ans =
74502
その他の回答 (1 件)
Shreya Shetty
2019 年 7 月 26 日
編集済み: madhan ravi
2019 年 7 月 26 日
Go through this. It might help you
1 件のコメント
madhan ravi
2019 年 7 月 26 日
編集済み: madhan ravi
2019 年 7 月 26 日
No, indices should be determined by the code and not by giving it manually.
参考
カテゴリ
Help Center および File Exchange で Tables についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!