フィルターのクリア

matlab 2nd min question

1 回表示 (過去 30 日間)
rohit venkat gandhi
rohit venkat gandhi 2013 年 6 月 7 日
I have a matrix of 7000 * 7000 in which it contains 0 value and other random ones.(only positive integers). what i want is to identify the minimum value excluding zero and subtract it from all other values, and then compute using my formulas. What i want is that the operation should not touch zero at all. It should leave it as it is....
The output i should get such that nothing happens to zeros but for remaining the min value is identified and subtracted from all.. zero should be left as it is. Dont consider it

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 7 日
編集済み: Azzi Abdelmalek 2013 年 6 月 7 日
A=[1 0 2;3 4 5;0 0 4]
b=A(:);
b=b(b~=0)
val=min(b)
%or
B=A
B(B==0)=inf;
[min_val,idx]=min(B(:))
  2 件のコメント
rohit venkat gandhi
rohit venkat gandhi 2013 年 6 月 7 日
can you elaborate and explain me this please? iam a beginner in matlab
Azzi Abdelmalek
Azzi Abdelmalek 2013 年 6 月 7 日
B=A
B(B==0)=inf; % replace all zero values by inf
[min_val,idx]=min(B(:)) % min_value is the smallest value in B and idx is its corresponding index

サインインしてコメントする。


Iain
Iain 2013 年 6 月 7 日
編集済み: Iain 2013 年 6 月 7 日
A(A~=0) = A(A~=0) - min(A(A~=0));
This sets each element of A's elements NOT equal to zero equal to A's elements NOT equal to zero, minus the minimum of A's elements NOT equal to 0.

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by