How do I take the average of a zeros vector without dividing by the unpopulated zeros?
이전 댓글 표시
I am using real time data coming in and it is being populated into a matrix of zeros. I have the current code...
handles.vxdata= zeros(2400)
handles.speedmax= max(handles.vxdata)
%This works perfect b/c it just picks the max value out of the zeros vector
handles.speedavg=mean(handles.vxdata)
%I am having trouble with this command because it is taking my matrix of zeros and dividing by all the values in the vector, including the zeros that have not been populated with real time data.
I am looking to create a command that only uses the data in the matrix that has values.
채택된 답변
추가 답변 (1개)
Walter Roberson
2013년 3월 12일
If you are using a vector instead of a matrix, then
handles.speedavg = mean(nonzeros(handles.vxdata));
카테고리
도움말 센터 및 File Exchange에서 Number Theory에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!