Filling iteration with NaN when output argument is not assigned a value in execution of function.
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a plot with acceleration data vs time (in frames). There are certain regions of this plot that have features of interest like threshold crossings. To find the threshold crossings I have found the endpoints of a possible feature appearance and created several ranges of values, both acceleration and time, for which to search for the presence of a threshold crossing and if present document the time it occurs at. The issue arises when there is a range that doesn't have a crossing at the specified threshold (25). The result is the error "Output argument "xv" not assigned a value in the execution with FindLevel function". I understand it is giving me this error because it can't find a value in the range, however, instead of stopping the loop I want it to assign a NaN value instead and then move onto the next iteration. I tried making a conditional statement where it looks at an array containing the minimum value of each range and then if the minimum value exceeds the threshold it is assigned the value NaN, but I haven't been able to apply/connect this to the threshold finding part of the loop.
for i=1:size(CoMStartRangeAcc,1)
if (MinArray(i,:)>25)%the idea here is if the min acceleration value is below the threshold it isn't crossed and should be filled with an NAN
final(i,:)=NaN
else
FrameTimeComstart=FindLevel(CoMStartRangeFrame(i,:),CoMStartRangeAcc(i,:),25)
RowMakerComstart=FrameTimeComstart(1,1).';
final(i,:)=RowMakerComstart;
end
end
function xv = FindLevel(x,y,level) %the function I am using to find the threshold crossing times
cxi = find(diff(sign(y-level)));
for k = 1:numel(cxi)
idxrng = max(1,cxi(k)-1) : min(numel(x), cxi(k)+1);
xv(k) = interp1(y(idxrng), x(idxrng), level);
end
end
0 Commenti
Risposta accettata
Walter Roberson
il 25 Ago 2022
Inside the function, initialize
xv = nan;
Then if you do not assign anything else inside the loop, xv will still have been assigned a value.
1 Commento
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Introduction to Installation and Licensing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!