How to add values from if statements to a column

29 ビュー (過去 30 日間)
jacob Mitch
jacob Mitch 2019 年 10 月 9 日
コメント済み: jacob Mitch 2019 年 10 月 9 日
say I have
function [x,y]=valuesof(data)
input= data;
t=length(data);
for z=2:t
if input(z-1)>input(z) && input (z)<input(z+1);
x= 'the values of the indices' i.e z
y= 'the input values of the sequence that satisfies the condition' input(z)
end
end
end
how would I create a new colum for each value that satifies my if statement. The 1st column for the indice that the if statement is valid and the 2nd column for the value of input(z)
so for example if I have data of a column as
1
-3
1
0
-1
3
it would store the values of x
as
2
5
and y as
-3
-1
I would not like to use any built in matlab functions such as diff, sign and find etc. Thanks for the help

採用された回答

Turlough Hughes
Turlough Hughes 2019 年 10 月 9 日
編集済み: Turlough Hughes 2019 年 10 月 9 日
You just have to make an index for every time your if statement is satisfied. See the modified code.
function [x,y]=valuesof(data)
c=1; % new index
input= data;
t=length(data);
for z=2:t
if input(z-1)>input(z) && input(z)<input(z+1);
x(c,1)=z;
y(c,1)=input(z);
c=c+1;
end
end
end
  1 件のコメント
jacob Mitch
jacob Mitch 2019 年 10 月 9 日
Perfect this is exactly what i was looking for.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by