How do I replace zeroes in a <logical> 0 and 1 array with NaNs?

12 ビュー (過去 30 日間)
Tessa
Tessa 2014 年 12 月 9 日
回答済み: Tessa 2014 年 12 月 9 日
Hey,
I have a logical array with ones and zeroes and now I would like to replace the zeroes with NaNs but can´t find the right commend.
A(A==0) = nan; NaN's cannot be converted to logicals.
A(~A) = NaN; NaN's cannot be converted to logicals.
Also tried this: A=num2cell(A);
Who can help me out?
Greetings, A matlab hero :) A=num2cell(A);

採用された回答

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2014 年 12 月 9 日
編集済み: Giorgos Papakonstantinou 2014 年 12 月 9 日
It didn't work because you were trying to replace logical values (the zeros/false) with doubles (the NaN). So first, convert the A array to double.
A = double(A);
A(A==0) = NaN; % or A(~A)=NaN
Of course A will not be a logical anymore.

その他の回答 (1 件)

Tessa
Tessa 2014 年 12 月 9 日
Hero! Thank you :)

カテゴリ

Help Center および File ExchangeAnalysis of Variance and Covariance についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by