How to replace the zero with NaN in the specific column of cell arrays?
6 views (last 30 days)
Show older comments
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 on 5 Nov 2022
Edited: VBBV on 5 Nov 2022
S = load(websave('I','https://in.mathworks.com/matlabcentral/answers/uploaded_files/1182108/I.mat'))
K = cell2mat(S.I(:,1));
idx = find(K(:,2:3) == 0);
K(idx,2:3) = NaN
More Answers (1)
KSSV on 5 Nov 2022
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
Find more on Numeric Types in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!