フィルターのクリア

How to put a variable equal to a vector in an if cycle

2 ビュー (過去 30 日間)
AlexDp
AlexDp 2019 年 9 月 16 日
コメント済み: AlexDp 2019 年 9 月 17 日
Hi all,
i'm trying to to find a way to have this example:
for t=2:365
TIMEFAILURECOG= [2 4 10 50];
Matrixdiff=[0,TIMEFAILURECOG];
DIFFERENCE=diff(Matrixdiff);
INDEXCOG1=find(DIFFERENCE>2);
INDEXCOG2=find(DIFFERENCE<=2);
DD=TIMEFAILURECOG(1,INDEXCOG1);
BB=TIMEFAILURECOG(1,INDEXCOG2);
if t==TIMEFAILURE(1,INDEXCOG1) % for every t equal to each value of TIMEFAILURECOG(1,INDEXCOG1)
y=6;
elseif t==TIMEFAILURECOG(1,INDEXCOG2) % for every t equal to each value of TIMEFAILURECOG(1,INDEXCOG2)
y=4;
else
y=0;
end
end
Thanks to anyone who can help me!

採用された回答

Fabio Freschi
Fabio Freschi 2019 年 9 月 17 日
編集済み: Fabio Freschi 2019 年 9 月 17 日
My guess
% your data
TIMEFAILURECOG= [2 4 10 50];
Matrixdiff=[0,TIMEFAILURECOG];
DIFFERENCE=diff(Matrixdiff);
INDEXCOG1=find(DIFFERENCE>2);
INDEXCOG2=find(DIFFERENCE<=2);
DD=TIMEFAILURECOG(1,INDEXCOG1);
BB=TIMEFAILURECOG(1,INDEXCOG2);
% set t as a vector
t = 2:365;
% preallocate y as long as t
y = zeros(size(t));
% set y values according to t
y(ismember(t,DD)) = 6;
y(ismember(t,BB)) = 4;
  1 件のコメント
AlexDp
AlexDp 2019 年 9 月 17 日
Thank you very much Fabio! It's a great solution.

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

その他の回答 (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