Im trying to add values into an array using a for loop. This is my function but I hard coded it to work. Please help!
function[t1, t2, t3, t4, t5, t6, timeArr, maxArr, minArr, diagnosisArr] = findSinusArrhythmia(time, locationsR)
t1 = time(locationsR(7)) - time(locationsR(6));
t2 = time(locationsR(6)) - time(locationsR(5));
t3 = time(locationsR(5)) - time(locationsR(4));
t4 = time(locationsR(4)) - time(locationsR(3));
t5 = time(locationsR(3)) - time(locationsR(2));
t6 = time(locationsR(2)) - time(locationsR(1));
timeArr = [t1, t2, t3, t4, t5, t6];
maxArr = max(timeArr);
minArr = min(timeArr);
diagnosisArr = maxArr - minArr;
end

 採用された回答

David Hill
David Hill 2019 年 10 月 1 日

0 投票

t=diff(Time(fliplr(locationsR)));
maxT=max(t);
minT=min(t);
diagT=maxT-minT;
No need for t1, t2, ... just index into t. I assume time is an array that you are indexing into. There is a matlab function called time, I would not use a variable named the same thing. I might not understand what you want to do. I suggest that you explain more fully.

1 件のコメント

Zaheer Bhojani
Zaheer Bhojani 2019 年 10 月 1 日
Thank you. That really helped!

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by