# MATLAB App Designer for Demostration

1 view (last 30 days)
Lam Ha on 8 Mar 2023
Commented: Lam Ha on 18 Mar 2023
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 on 15 Mar 2023
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
Lam Ha on 18 Mar 2023
Thank you for your nice instruction. That help me a lots.

### Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

R2021b

### Community Treasure Hunt

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

Start Hunting!