% Value changed function: ActionDropDown_2
function ActionDropDown_2ValueChanged(app, event)
if app.ActionDropDown_2.Value == "Plot"
app.Tbl = app.UITable2.Data(:,{'DATE', 'AVAILABILITY'});
app.X = app.UITable2.Data(:,3);
app.Y = app.UITable2.Data(:,31);
plot(app.UIAxes,app.X,app.Y)
end
end
The callback function operates as expected, once called, the debug arrow reaches breakpoint of the IF statment line but once I chose to "Continue" the debug arrow jumps straight to END. Not executing any of the following lines to define Tbl, X, or Y and no plot.

댓글 수: 6

shnrndll
shnrndll 2022년 1월 5일
Data is an x by 31 table, the table holds several variables but the relevant variables are DATE, 3rd column and, AVAILABILITY, 31st column
Voss
Voss 2022년 1월 5일
Seems like app.ActionDropDown_2.Value is not equal to "Plot".
shnrndll
shnrndll 2022년 1월 5일
Yes, but why is of question, the line of code seems correct
Cris LaPierre
Cris LaPierre 2022년 1월 5일
The code is syntatically correct, and you are not getting any errors. The issue is that the condition evaluates as false, so the code inside the statement does not get run.
shnrndll
shnrndll 2022년 1월 5일
Well the IF condition line equates to Plot, during debugging, the breakpoint of this line displayed ".Value" equating to Plot
Put a breakpoint at the if. When you arrive there, command
class(app.ActionDropDown_2.Value)
if char(app.ActionDropDown_2.Value)
disp('char')
disp(double(app.ActionDropDown_2.Value))
elseif isstring(app.ActionDropDown_2.Value)
disp('string')
disp(double(app.ActionDropDown_2.Value{1}))
else
disp('other')
disp(app.ActionDropDown_2.Value)
end
and tell us what the output is.
This is not intended as permanent code: it is only intended to help debug the problem.

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

 채택된 답변

Image Analyst
Image Analyst 2022년 1월 5일

0 개 추천

You need to check the index of the drop down list, or else get the selected string and compare the that string (only) to "Plot" using the contains() function:
% Value changed function: ActionDropDown_2
function ActionDropDown_2ValueChanged(app, event)
% Check the index of the selected item.
selectedIndex = app.ActionDropDown_2.Value;
% Method #1:
%if selectedIndex == 3 % or whatever number in the list it is.
% Rest of "if" block follows...
% Or use Method #2:
% Check the selected string. First get all strings in the list.
allStrings = app.ActionDropDown_2.String;
% Get the specific one that was selected.
selectedString = allStrings{selectedIndex};
% See if it says "Plot".
if contains(selectedString, "Plot", 'IgnoreCase', true)
% They chose plot, so do the plotting.
app.Tbl = app.UITable2.Data(:,{'DATE', 'AVAILABILITY'});
app.X = app.UITable2.Data(:,3);
app.Y = app.UITable2.Data(:,31);
plot(app.UIAxes,app.X,app.Y)
end
end

댓글 수: 3

What do you notice if we simplify it to
app.X = app.UITable2.Data(:,3);
app.Y = app.UITable2.Data(:,31);
whos app.X % Look in command window for this
whos app.Y % Look in command window for this
app.s = scatter(app.X, app.Y); % Might plot in some different axes control though
What do you see in the command window, and on your GUI? The data types should be there inthe command window, plus any error messages.
shnrndll
shnrndll 2022년 1월 6일
Thank you I solved this with you code

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2022년 1월 5일

댓글:

2022년 1월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by