% Value changing function: STARTKnob_2
function STARTKnob_2ValueChanging(app, event)
arguments
app
event.Value(1,1) {mustBeNumeric}=0
end
app.StartYear = event.Value;
if app.StartYear>app.StopYear-1 %checks the increasing-xrule
app.StopYear=min([app.StartYear+1,app.STOPKnob.Limits(2)]);
app.STOPKnob.Value=app.StopYear; %rotate the stop knob
app.StartYear=app.StopYear-1;
app.STARTKnob_2.Value=app.StartYear;
end
app.plotData();
end
% Value changing function: STOPKnob
function STOPKnobValueChanging(app, event)
arguments
app
event.Value(1,1) {mustBeNumeric}=0
end
app.StopYear = event.Value;
if app.StopYear<app.StartYear+1
app.StartYear=max([app.StopYear-1 app.STARTKnob_2.Limits(1)]);
app.STARTKnob_2.Value=app.StartYear;
app.StopYear=app.StartYear+1;
app.STOPKnob.Value=app.StopYear;
end
app.plotData();

4 Kommentare

Mukesh
Mukesh am 22 Mär. 2025
Even after defining the upper and lower limits for xlim, why i am still getting the errror
VBBV
VBBV am 23 Mär. 2025
Verschoben: VBBV am 26 Mär. 2025
@Mukesh try with following change in these lines
app.StarYear.Value = event.Value
app.StopYear.Value = event.Value
xlim(app.UIAxes, [app.StartYear.Value app.StopYear.Value])
Mukesh
Mukesh am 25 Mär. 2025
Verschoben: VBBV am 26 Mär. 2025
Thanks for all your help. I have figured out how it was initialised to same value. While setting the parameters for knob, the lower limit for both start & stop was set to 1850 by default. Thats why both had same value. Now i have created default function and sent the intital parameters accordingly and called it in startup function.
VBBV
VBBV am 26 Mär. 2025
Bearbeitet: VBBV am 27 Mär. 2025
@Mukesh if you dont want the default values of xlim to be used,
then inside the function plotData you need to put the xlim line with manual first which will override the default values.
function plotData(app)
xlim(app.UIAxes, 'manual') % put this line first
%app.StarYear.Value = event.Value
%app.StopYear.Value = event.Value
xlim(app.UIAxes, [app.StartYear.Value app.StopYear.Value])

Melden Sie sich an, um zu kommentieren.

 Akzeptierte Antwort

Image Analyst
Image Analyst am 22 Mär. 2025

0 Stimmen

You need to debug your program. See
After that, when you see an error that says the limits of the min and max values you're passing into xlim must be increasing values, you'll know how to check their values. What you need to do is set a breakpoint at xlim and hover over app to see what the values of StartYear and StopYear are. Or else just put them in the code right before xlim
app.StartYear
app.StopYear % No semicolons!
xlim(app.UIAxes, [app.StartYear, app.StopYear])
What are their values?

7 Kommentare

Mukesh
Mukesh am 23 Mär. 2025
Thanks for suggestion.
Image Analyst
Image Analyst am 23 Mär. 2025
You said "Even after defining the upper and lower limits for xlim..." and I asked "what are their values?" You did not answer me. Why not? Did you try what I said?
Mukesh
Mukesh am 23 Mär. 2025
Yes i tried your way. Both have same value (i.e 1850) but i don't know how both the variables are initialised to same value.
Image Analyst
Image Analyst am 23 Mär. 2025
How about if you just don't call xlim and let it automatically decide what the limits should be?
Mukesh
Mukesh am 23 Mär. 2025
I am actually working on Appdesigner and these data need to be fixed so that i can plot the data
Image Analyst
Image Analyst am 23 Mär. 2025
Bearbeitet: Image Analyst am 23 Mär. 2025
So I assume that means you want the same start and stop values over multiple sets of data, instead of adjusting it on a vector-by-vector basis. But you're evidently setting them both to the same value.
Does your app have a startupFcn? If not, add one and set the app.Start and Stop to some default values. Or else use isempty() when you're trying to turn the knobs or plot data to make sure the start and stop values are not null.
Can you attach your GlobalTemp.mlapp so that I can fix it? Also a set of data if one is needed to run the program.
Mukesh
Mukesh am 25 Mär. 2025
Thanks for all your help. But I have figured out how it was initialised to same value. While setting the parameters for knob, the lower limit for both start & stop was set to 1850 by default. Thats why both had same value. Now i have created default function and sent the intital parameters accordingly and called it in startup function. But your debug idea helped a lot.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Walter Roberson
Walter Roberson am 22 Mär. 2025

0 Stimmen

You do not provide initial values for app.StartYear or app.StopYear, so they are initialized to [] (the empty vector)
Then when you test
if app.StartYear>app.StopYear-1
then app.StartYear = event.Value might have given a value to app.StartYear, but app.StopYear is still [] and testing (Value>[]) is false.

3 Kommentare

Mukesh
Mukesh am 23 Mär. 2025
Bearbeitet: Mukesh am 23 Mär. 2025
Considering above argument, error should be shown in function STARTKnob_2ValueChanging(app, event) or function STOPKnobValueChanging(app, event).
Why error is shown in xlim part(line 34)??
It is not an error to calculate with [] .
(It is typically an error to try to store [] into indexed locations. Not always though.)
With it not being an error to calculate with [], the error is not encounted until the call to
xlim(app.UIAxes, [app.StartYear app.StopYear])
with app.StopYear being [] the above call would collapse to
xlim(app.UIAxes, [app.StartYear []])
which would be
xlim(app.UIAxes, app.StartYear)
which would error because the input vector is only length 1.
Mukesh
Mukesh am 23 Mär. 2025
Actually i have checked their value. I dont know how both variables are initialised to same value. So i understood why i was getting the error since it is not increasing numeric value input for xlim but now i am not gettting how how both variables are initialised to same value

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Hilfe-Center und File Exchange

Produkte

Version

R2022b

Gefragt:

am 22 Mär. 2025

Bearbeitet:

am 27 Mär. 2025

Community Treasure Hunt

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

Start Hunting!

Translated by