How can I Read or get the Values one by one from matrix variable or array?

1 回表示 (過去 30 日間)
PRIYANGA
PRIYANGA 2012 年 7 月 13 日
Sir or Madam,
I want to read the array variable one by one from array or matrix? How can i write the code? I want to calculate the Zero Element and Non Zero Element in the matrix?
I have use s=nnz(x);
but i want to get the values one by one and the compare and calculate the zero and nonzero element.
thank you sir/madam.

採用された回答

TAB
TAB 2012 年 7 月 13 日
編集済み: TAB 2012 年 7 月 13 日
for x=1:length(YourMatrix)
if YourMatrix(x)==0
% Operation
elseif YourMatrix(x)~=0
% Operation
else
end
end
But vectorization is always recommended in matlab programming instead of using loop whenever possible.

その他の回答 (1 件)

Sebastian Holmqvist
Sebastian Holmqvist 2012 年 7 月 13 日
z_elem = nnz(nnz == 0)
nz_elem = nnz(nnz ~= 0)
Then do your calculations on each.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by