How to find values from data

When using if statements, I am trying to find a set of data that fits the condition I have given. How can I find where the data with the right conditions is located?

回答 (1 件)

KSSV
KSSV 2021 年 12 月 12 日

1 投票

You can use logical indexing.
Example:
A = rand(10,1) ; % data for demo
idx = A > 0.3 & A < 0.8 ;
idx
idx = 10×1 logical array
0 1 0 1 0 0 0 0 0 0
find(idx)
ans = 2×1
2 4
A(idx)
ans = 2×1
0.7124 0.7594

5 件のコメント

Zach Hanses
Zach Hanses 2021 年 12 月 12 日
how would I use this on if statments?
KSSV
KSSV 2021 年 12 月 12 日
You can go by logical indexing seperately; need not to use a if condition. If you insist:
A = rand(10,1) ;
for i = 1:10
if A(i) > 0.3 && A(i) < 0.8 % condition
A(i) % do this
end
end
ans = 0.5699
ans = 0.6995
ans = 0.3670
ans = 0.6272
ans = 0.3990
ans = 0.5883
Zach Hanses
Zach Hanses 2021 年 12 月 12 日
What if the two conditions were from two different datasets.
if A(i) > 0.3 && A(i) < 0.8 % condition
A(i) % do this
What would I put for the outcome of the if condition
This is what I have
for n = 1:length(aveDailyTemp)
if ((aveDailyTemp > 2) & (sevenDayAve < 1));
bestDatesToPlant(n)
Star Strider
Star Strider 2021 年 12 月 12 日
What are the row and column sizes are the two data sets? Do they have common times (or any other specific identifying row information)?
Zach Hanses
Zach Hanses 2021 年 12 月 12 日
they are both 244x1. Each row is supposed to indicate days

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

カテゴリ

ヘルプ センター および File ExchangeCell Arrays についてさらに検索

タグ

質問済み:

2021 年 12 月 12 日

コメント済み:

2021 年 12 月 12 日

Community Treasure Hunt

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

Start Hunting!

Translated by