Help saving the output of a for loop within a function into a vector.
Afficher commentaires plus anciens
Hello. I am currently writing the below function:
function [numout, outvec]= SCAN_DATA(vectin, lowlim, uplim)
%Compares each element of vectin against lowlim and uplim and returns
%a count (numout) of how many vector elements are greater than or less than the
%limits and a vector (outvec) of the actual out-of-limit readings
for k=1:length(vectin)
if vectin(k)>lowlim && vectin(k)<uplim;
outvec=vectin(k)
numout=numel(outvec)
else outvec=0
end
end
I would like to save the data output into the vector named vectin but I only get the last output run through the loop. I am pretty new to this after looking around online, I can't figure it out. Can anyone help?
Réponse acceptée
Plus de réponses (1)
Andrei Bobrov
le 24 Fév 2015
l0 = vectin>lowlim & vectin<uplim;
outvec = l0*vectin;
numout = nnz(l0);
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!