필터 지우기
필터 지우기

MATLAB App Designer for Demostration

조회 수: 1 (최근 30일)
Lam Ha
Lam Ha 2023년 3월 8일
댓글: Lam Ha 2023년 3월 18일
Hi everyone, I'm using Matlab App Designer to demostrate my experiment. (Picture attached below)
My demostration based on the data collected from my sensor and from this I can know exactly the position of the kicking one.
For example, if the data in sensor 3 is high, it means the kicking point is the point 1 (The nearest position compared to sensor 3).
Why I try to changing the color of the Lamp in the point 2, it doesn't work well.
Please show me how to do that. Thank you so much everyone.
This is the code I used. Which A3 is the data from sensor 1, B3 is the data from sensor 2, C3 is the data from sensor 3

채택된 답변

Shushant
Shushant 2023년 3월 15일
According to my understanding of the issue, you want your sensors to light up as "green" or "red" based on some specific conditions for instance if "C3" is the greatest value in a particular interval say "1-15" then the "Lamp3" will become "red" but if "B3" is the greatest then "Lamp4" will become "red". If this is what you were trying to achieve then according to the code provided by you, I only see one condition in the interval "1-15" in which if "C3" is the greatest value then your code will work fine and "Lamp3" will become "red" but if that is not the case then nothing will happen for that duration i.e., "1-15" and all lamps will remain "green" in that duration, same issue with all other durations "30-45" and "45-60".
I would recommend that you put all your conditions inside a function and call that function which checks for all the appropriate conditions and lights up the lamp which satisfies the correct condition. As an example, look at the below code snippet.
A3 = 5-(5+5)*rand(60,1);
B3 = 5-(5+5)*rand(60,1);
C3 = 5-(5+5)*rand(60,1);
LamptoLight(A3,B3, C3, 1, 15);
From 1 to: 15 Lamp1: red Lamp2: green Lamp3: green Lamp4: green
LamptoLight(A3,B3, C3, 15, 30);
From 15 to: 30 Lamp1: green Lamp2: green Lamp3: red Lamp4: green
LamptoLight(A3,B3, C3, 30, 45);
From 30 to: 45 Lamp1: green Lamp2: red Lamp3: green Lamp4: green
LamptoLight(A3,B3, C3, 45, 60);
From 45 to: 60 Lamp1: green Lamp2: green Lamp3: red Lamp4: green
function LamptoLight(A3, B3, C3, from, to)
Lamp1 = 'green';
Lamp2 = 'green';
Lamp3 = 'green';
Lamp4 = 'green';
if ((abs(mean(C3(from:to)))>abs(mean(B3(from:to)))) && (abs(mean(C3(from:to)))>abs(mean(A3(from:to)))))
Lamp1 = 'green';
Lamp2 = 'green';
Lamp3 = 'red';
Lamp4 = 'green';
elseif ((abs(mean(B3(from:to)))>abs(mean(C3(from:to)))) && (abs(mean(B3(from:to)))>abs(mean(A3(from:to)))))
Lamp1 = 'green';
Lamp2 = 'green';
Lamp3 = 'red';
Lamp4 = 'green';
elseif ((abs(mean(A3(from:to)))>abs(mean(B3(from:to)))) && (abs(mean(B3(from:to)))>abs(mean(C3(from:to)))))
Lamp1 = 'green';
Lamp2 = 'red';
Lamp3 = 'green';
Lamp4 = 'green';
elseif ((abs(mean(A3(from:to)))>abs(mean(C3(from:to)))) && (abs(mean(C3(from:to)))>abs(mean(B3(from:to)))))
Lamp1 = 'red';
Lamp2 = 'green';
Lamp3 = 'green';
Lamp4 = 'green';
end
disp("From "+from+" to: "+to );
disp("Lamp1: "+Lamp1);
disp("Lamp2: "+Lamp2);
disp("Lamp3: "+Lamp3);
disp("Lamp4: "+Lamp4);
end
  댓글 수: 1
Lam Ha
Lam Ha 2023년 3월 18일
Thank you for your nice instruction. That help me a lots.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by