Help saving the output of a for loop within a function into a vector.
显示 更早的评论
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?
采纳的回答
更多回答(1 个)
Andrei Bobrov
2015-2-24
l0 = vectin>lowlim & vectin<uplim;
outvec = l0*vectin;
numout = nnz(l0);
类别
在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!