Finding minima using if and for loops

2 ビュー (過去 30 日間)
Elijah L
Elijah L 2020 年 9 月 16 日
コメント済み: BOB MATHEW SYJI 2020 年 9 月 16 日
I have a column of data and I want to make a script that utilizes for loops and if constructs
for example
12
4
5
23
63
57
23
6
34
In this set, the minima would be 4 and 6

採用された回答

BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 16 日
編集済み: BOB MATHEW SYJI 2020 年 9 月 16 日
Hope this helps. Vector y returns the minimum values of vector A
A=[12; 4; 5; 23; 63; 57; 23; 6; 34];
a=A';
d=[diff(a) 0];
c=[];
for i=1:(length(d)-1)
if d(i)*d(i+1)<0&&d(i+1)>0
c=[c (i+1)];
end
end
for j=1:length(c)
y(j)=a(c(j));
end
  2 件のコメント
Star Strider
Star Strider 2020 年 9 月 16 日
This is homework.
We have a policy of providing only hints for homework. It is not appropriate to provide complete solutions.
BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 16 日
I am sorry. I did not know of that. I will do that in future

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by