I have a matrix that is about 3000x7, containing either a number or a zero. I'd like to get the log2 value of each number, but if the value was zero, I'd like for it to ignore that value.
What I have tried initally: if matrix>0 log2(matrix); else matrix==0; end
I know I'm most likely no where close to correct, but I'm still very new to Matlab. Any help would be appreciated! Thank you!

 採用された回答

John D'Errico
John D'Errico 2017 年 5 月 23 日

0 投票

If statements don't work that way. They don't allow you to treat each element of the matrix independently.
matrix2 = zeros(size(matrix));
ind = matrix > 0;
matrix2(ind) = log2(matrix(ind));

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

タグ

質問済み:

2017 年 5 月 23 日

回答済み:

2017 年 5 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by