MATLAB App Designer for Demostration
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1317785/image.png)
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
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1317790/image.png)
0 Kommentare
Akzeptierte Antwort
Shushant
am 15 Mär. 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);
LamptoLight(A3,B3, C3, 15, 30);
LamptoLight(A3,B3, C3, 30, 45);
LamptoLight(A3,B3, C3, 45, 60);
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
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!