How can I find a data (number) within variable based on a condition…!

1 回表示 (過去 30 日間)
Loran
Loran 2014 年 9 月 14 日
コメント済み: Image Analyst 2014 年 9 月 14 日
Hello,
I am new to Matlab with very little experience!
I have a variable set with 5 columns, and I am trying to get a data from one column based on the condition of other column..
For example, I like to get the corresponding value in column 5 based on column 3.
while i = 50 in column 3 find the value of 22 from column 5? By changing i, get the corresponding number from column 5?
1400 1 1 3 11
1500 2 50 5 22
1600 3 100 7 33
1700 4 200 9 44
…..
Thanks so much!
Regards’
Loran

回答 (1 件)

Image Analyst
Image Analyst 2014 年 9 月 14 日
Try this:
m=[...
1400 1 1 3 11;
1500 2 50 5 22;
1600 3 100 7 33;
1700 4 200 9 44]
col3equals50 = m(:,3)==50 % Logical vector of where column 3 value = 50
extractedCol5Numbers = m(col3equals50, 5)
In the command window:
m =
1400 1 1 3 11
1500 2 50 5 22
1600 3 100 7 33
1700 4 200 9 44
col3equals50 =
0
1
0
0
extractedCol5Numbers =
22
  2 件のコメント
Loran
Loran 2014 年 9 月 14 日
Great, thanks so much. Appreciated! :) Loran
Image Analyst
Image Analyst 2014 年 9 月 14 日
You're welcome. You can also thank by officially "Accepting" and voting for the answer.

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by