How to replace the zero with NaN in the specific column of cell arrays?

5 ビュー (過去 30 日間)
BN
BN 2022 年 11 月 5 日
編集済み: VBBV 2022 年 11 月 5 日
Hello,
I have a cell (1*5) with some 0 in the second and third columns in each cell array; I want to know how to replace all these zeros (only in second and third columns, not the first one) with NaN. I attached the cell.
Thank you so much

採用された回答

VBBV
VBBV 2022 年 11 月 5 日
編集済み: VBBV 2022 年 11 月 5 日
S = load(websave('I','https://in.mathworks.com/matlabcentral/answers/uploaded_files/1182108/I.mat'))
S = struct with fields:
I: {[444×3 double] [444×3 double] [444×3 double] [444×3 double] [444×3 double]}
K = cell2mat(S.I(:,1));
idx = find(K(:,2:3) == 0);
K(idx,2:3) = NaN
K = 888×3
132.6478 44.0000 40.0000 125.3750 NaN NaN 123.1060 NaN NaN 68.5260 NaN NaN 41.6045 NaN NaN 42.0444 NaN NaN 68.8907 NaN NaN 62.8754 NaN NaN 55.9440 NaN NaN 58.4338 NaN NaN

その他の回答 (1 件)

KSSV
KSSV 2022 年 11 月 5 日
Let A be your m*3 array.
A(A(:,2)==0,2)=NaN ; % repalce second column with NaN's
A(A(:,3)==0,3)=NaN ; % replace third column with NaN's

カテゴリ

Help Center および File ExchangeGraph and Network Algorithms についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by