compare integer values

12 ビュー (過去 30 日間)
Bayan
Bayan 2012 年 2 月 15 日
編集済み: Matt J 2013 年 10 月 13 日
How i can compare between each element in specific matrix and constant value as 0.5 and then take action if the result true .

採用された回答

Image Analyst
Image Analyst 2012 年 2 月 15 日
You mean something like this:
% Make some sample data.
m=rand(1, 10)
% See where it exceeds 0.5.
biggerThanPoint5 = m > 0.5
% Make some other array that we want to act upon.
out = 11 * ones(1,10)
% Set out = 99 where m>0.5
out(biggerThanPoint5) = 99
Results in command window:
m =
0.4898 0.4456 0.6463 0.7094 0.7547 0.2760 0.6797 0.6551 0.1626 0.1190
biggerThanPoint5 =
0 0 1 1 1 0 1 1 0 0
out =
11 11 11 11 11 11 11 11 11 11
out =
11 11 99 99 99 11 99 99 11 11
  1 件のコメント
Bayan
Bayan 2012 年 2 月 15 日
thanks a lot ^_^

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

その他の回答 (1 件)

Honglei Chen
Honglei Chen 2012 年 2 月 15 日
Say you have the matrix A, and you have a function foo contains the operation you'd like to apply to elements of A if they equal to 0.5, you can do
A(A==0.5) = arrayfun(@foo,A(A==0.5))

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by