how can I set spinner limit range based on text box entry ?

4 次查看(过去 30 天)
I have a gui with a spinner in it
I would like to input a value in a text box and use it as upper limit for the spinner
can't find a way to do it. It seems the function does not read the text entry
here is my code for the text box
function RECdurationminTextAreaValueChanged(app, event)
REC = app.RECdurationminTextArea.Value;
app.selectminuteSpinner.Limits = [0 REC];
end
and here for the spinner
function selectminuteSpinnerValueChanged(app, event)
value = app.selectminuteSpinner.Value;
end
however when I run it I get this error when I try to scroll the spinner up or down:
Error using matlab.ui.control.internal.model.PropertyHandling.validateLimitsInput (line 721)
'Limits' must be a 1-by-2 increasing array of real numbers, such as [0 100]. Use -Inf and/or Inf to indicate no bound for the lower and/or upper limit.
Error in matlab.ui.control.internal.model.AbstractNumericComponent/set.Limits (line 225)
rowVectorLimits = matlab.ui.control.internal.model.PropertyHandling.validateLimitsInput(obj, newValue);

采纳的回答

Vimal Rathod
Vimal Rathod 2020-7-6
Hi,
Firstly you could check if your text box returns which type of data. The value you get from a normal textbox is a char or string value unless it is a numerical textbox. Try using "str2double" function before assigning the spinner limits.
REC = app.RECdurationminTextArea.Value;
% assign 2nd index(Upper Limit) of limits.
app.selectminuteSpinner.Limits(2) = str2double(REC); %str2double
Refer to the following link to know more about numeric edit field
  1 个评论
LO
LO 2020-7-6
Thanks Vimal
in fact I was using a non numeric editor
however the trouble of the spinner now is another: it lags behind so I cannot use the "last number displayed" by the spinner but only the one before. which makes it impossible to use the spinner value bidirecetionally and with accuracy. At least according to what I understood so far
Thanks though

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 System Commands 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by