what is wrong with this small app?

조회 수: 1 (최근 30일)
Muazma Ali
Muazma Ali 2023년 4월 8일
답변: Praveen Reddy 2023년 4월 10일
Hi
I am trying to play around with my small list in this app but it seems matlab is not accepting my code.
Can anybody tell me whats wrong in it?
  댓글 수: 2
Matt J
Matt J 2023년 4월 8일
What would we need to do to observe the problem?
Muazma Ali
Muazma Ali 2023년 4월 10일
hi @Matt J when I choose the first three elements from the list, the lamp is supposed to to turn to green. But I think I havent set up the criterion right in the app...
Could you check it , I would be very thankful. Actually I had programmed a list in my matlab program with result coming up as numbers and based on those numbers I had set up some conditions but when I started on the app, I had to use the list from the canvas then I could nt use the programmed once, :(

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

답변 (1개)

Praveen Reddy
Praveen Reddy 2023년 4월 10일
Hi Mauzama,
I understand that you want to make the lamp glow green whenever user selects the first three values from the “ListBox”. In the call back function I could observe that you are comparing “value” with string, but “value” is a cell array of all the selected items.
if (strcmpi(value, 'CaCl2') && strcmpi(value,'MgCl2') && strcmpi(value, 'NH4Cl'))
app.Lamp.Color='g';
else
app.Lamp.Color='r';
end
Modify the if condition in the call back function as below
% Value changed function: ListBox
function ListBoxValueChanged(app, event)
value = app.ListBox.Value;
if(any(ismember(value,'CaCl2')) && any(ismember(value,'MgCl2')) && any(ismember(value,'NH4Cl')))
app.Lamp.Color='g';
else
app.Lamp.Color='r';
end
end
To know more about “ismember” and “any” functions, please refer to the following MATLAB documentation
I hope the above information resolves your query.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by