Can I make a counter in App Designer?

10 views (last 30 days)
Hi, I'm trying to make an app using App Designer that shows different phases of processing on a signal. The user will be able to configure radio button selections and drop down values such that a specific signal will be chosen when the user clicks the Run button.
The idea is that after the user configures for a specific signal and hits the Run button, the signal is shown before it is processed. Then I wish to use (arrows or) a Back button and a Forward button to show how the signal transforms during processing for fixed increments of time.
The way I hoped to accomplish this is by using a counter variable, Cnt, to increment or decrement based on if the Back or Forward button is clicked respectively.
This is a test app I've been trying. It shows either a vertical line or horizontal line based on if A or B is chosen respectively, and the Run button is clicked. The Back and Forward Button respectively decreases or increases the number of lines horizontally or vertically based on if it is A or B chosen.
This is my callback code for the Run Button:
Ch = app.Choices.SelectedObject;
app.UIAxes.XAxis.Limits = [0 100];
app.UIAxes.YAxis.Limits = [0 100];
switch Ch
case app.Achoice
a = [10 10 10 10 10];
b = [5 30 55 80 95];
plot(app.UIAxes,a,b)
case app.Bchoice
d = [10 10 10 10 10];
e = [5 30 55 80 95];
plot(app.UIAxes,e,d)
end
For the Forward button callback:
Ch = app.Choices.SelectedObject;
app.UIAxes.XAxis.Limits = [0 100];
app.UIAxes.YAxis.Limits = [0 100];
app.cnt = app.cnt + 1;
if Ch == app.AChoice
if app.cnt == 1
a = [10 10 10 10 10];
b = [5 30 55 80 95];
plot(app.UIAxes,a,b)
hold on
a1 = [30 30 30 30 30];
plot(app.UIAxes,a1,b)
elseif app.cnt == 2
a = [10 10 10 10 10];
b = [5 30 55 80 95];
plot(app.UIAxes,a,b)
hold on
a1 = [30 30 30 30 30];
plot(app.UIAxes,a1,b)
hold on
a2 = [50 50 50 50 50];
plot(app.UIAxes,a2,b)
elseif app.cnt == 3
a = [10 10 10 10 10];
b = [5 30 55 80 95];
plot(app.UIAxes,a,b)
hold on
a1 = [30 30 30 30 30];
plot(app.UIAxes,a1,b)
hold on
a2 = [50 50 50 50 50];
plot(app.UIAxes,a2,b)
hold on
a3 = [70 70 70 70 70];
plot(app.UIAxes,a3,b)
elseif app.cnt == 4
a = [10 10 10 10 10];
b = [5 30 55 80 95];
plot(app.UIAxes,a,b)
hold on
a1 = [30 30 30 30 30];
plot(app.UIAxes,a1,b)
hold on
a2 = [50 50 50 50 50];
plot(app.UIAxes,a2,b)
hold on
a3 = [70 70 70 70 70];
plot(app.UIAxes,a3,b)
hold on
a4 = [90 90 90 90 90];
plot(app.UIAxes,a4,b)
else
errordlg('','Too High')
end
elseif Ch == app.BChoice
if app.cnt == 1
d = [10 10 10 10 10];
e = [5 30 55 80 95];
plot(app.UIAxes,e,d)
hold on
d1 = [30 30 30 30 30];
plot(app.UIAxes,e,d1)
elseif app.cnt == 2
d = [10 10 10 10 10];
e = [5 30 55 80 95];
plot(app.UIAxes,e,d)
hold on
d1 = [30 30 30 30 30];
plot(app.UIAxes,e,d1)
hold on
d2 = [50 50 50 50 50];
plot(app.UIAxes,e,d2)
elseif app.cnt == 3
d = [10 10 10 10 10];
e = [5 30 55 80 95];
plot(app.UIAxes,e,d)
hold on
d1 = [30 30 30 30 30];
plot(app.UIAxes,e,d1)
hold on
d2 = [50 50 50 50 50];
plot(app.UIAxes,e,d2)
hold on
d3 = [70 70 70 70 70];
plot(app.UIAxes,e,d3)
elseif app.cnt == 4
d = [10 10 10 10 10];
e = [5 30 55 80 95];
plot(app.UIAxes,e,d)
hold on
d1 = [30 30 30 30 30];
plot(app.UIAxes,e,d1)
hold on
d2 = [50 50 50 50 50];
plot(app.UIAxes,e,d2)
hold on
d3 = [70 70 70 70 70];
plot(app.UIAxes,e,d3)
hold on
d4 = [90 90 90 90 90];
plot(app.UIAxes,e,d4)
else
errordlg('','Too High')
end
else
errordlg('','Stuff')
end
Similar code is written for the Back button. I made the counter variable, cnt, a private property. Now the error I receive for my file, Arrow_Try.mlapp is: No appropriate method, property, or field 'AChoice' for class 'Arrow_try'.
Please help me. I have never used a counter before in App Designer.
  2 Comments
Raees Mohammed
Raees Mohammed on 31 Jan 2018
Also, I did not specify the minimum and maximum values for the cnt variable.
Raees Mohammed
Raees Mohammed on 31 Jan 2018
This was the private property I made for the cnt variable:
properties (Access = private)
cnt = 0; % Description
end

Sign in to comment.

Accepted Answer

Matt J
Matt J on 31 Jan 2018
Edited: Matt J on 31 Jan 2018
The error message you've shown doesn't appear to be connected with 'cnt' at all. It's complaining that it doesn't recognzie "app.AChoice" . Check that app.AChoice returns what it's supposed to.
  1 Comment
Raees Mohammed
Raees Mohammed on 31 Jan 2018
Yup, you're right. I figured out that was one of the problems. It was supposed to be "app.Achoice" in my code.
I got it to work after that, so my counter works.

Sign in to comment.

More Answers (0)

Categories

Find more on App Building in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!