필터 지우기
필터 지우기

using mean function to return a singular value of a row vector

조회 수: 1 (최근 30일)
Jack
Jack 2023년 10월 26일
편집: Walter Roberson 2023년 10월 26일
I have made a function that reads the mositure of soil using a soil sensor and I call this function in a main scripit to use the soil mositure how ever when I call the function in my main scripit I get 3 numbers returned to me from my function and am not sure why . My goal is to only get a single value returned to me from the function I call .was hoping someone could help me get the avg of the row vector x to be a singular value. I have posted my function I use to get the soil moisture reading :
function code :
function Current_soil_moisture =get_SoilMoisture(Object);
%this function reads the volatge of the capactive mositure sensor , it reads the sensor volatge 8 times and stores the reading in a row vector
% the avg of the volatge readings in the row vector is taken using mean function, the mean of the row vector gives us a more accuate reading of the sensor volatage
i =1;
while i==1
V1= readVoltage(Object,'A1');
V2=readVoltage(Object,'A1');
V3=readVoltage(Object,'A1');
V4=readVoltage(Object,'A1');
V5=readVoltage(Object,'A1');
V6=readVoltage(Object,'A1');
V7=readVoltage(Object,'A1');
V8=readVoltage(Object,'A1');
x=[V1 V2 V3 V4 V5 V6 V7 V8];
X=mean(x,"all");
i=i+1;
end
Current_soil_moisture = X;
fprintf('\n The current_soil_moisture is: \n %.2f',Current_soil_moisture )
and here is what I get in the command window when i call it

채택된 답변

Sam Chak
Sam Chak 2023년 10월 26일
Hi Jack,
It could be the get_SoilMoisture(Object) function is nested in a for-loop that performs 3 iterations in the Main Script. Please check.
  댓글 수: 2
Jack
Jack 2023년 10월 26일
Hey thats what i was wondering to ive attcahed my main scrpit , i think my error is on line 141 as maybe the function isnt under the if get_SoilMoisture(Object) statement how ever im not sure , let me know what you think !
Jack
Jack 2023년 10월 26일
oh wait i think i found my issue I was following my code wrong

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Agriculture에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by