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!