MATLAB: Adding numbers to an array

arrayecg

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

Best Answer

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.
Related Question