gui popupmenu problem with limits

Hello, I want to create an app that counts the limit of a function at an exact point. I need to use a popup menu to select whether the border is to the right or left. There's my code, why isn't it working? Could you help me?
function mat
f = figure('Visible','off',...
'Position',[480,500,500,480]);
pushbutton = uicontrol('Style','pushbutton',...
'String','count',...
'Position',[285,63,70,25],...
'Callback',@border);
hinput_g = uicontrol('Style','edit',...
'Position',[120, 200,240,35],...
'String','function','FontSize',13, 'FontName','silom');
hinput_granica = uicontrol('Style','edit',...
'Position',[120, 100,240,35],...
'String','limit at point','FontSize',13);
hpopup_g = uicontrol('Style','popup',...
'String',{'right','left'},...
'Position',[130,50,140,35]);
set(f,'Name','My app gui');
set(f,'Visible','on');
function border(~,~)
x = get(hinput_g,'String');
x = str2sym(x);
a = get(hinput_granica, 'String')
a = str2num(a);
idx = get(hpopup_g,'Value');
str = get(hpopup_g, 'String');
popup_str = str{idx};
if popup_str == 'right'
c = limit(x, a,'right');
msgbox(sprintf(char(c)));
elseif popup_str == 'left'
c = limit(x, a,'left');
msgbox(sprintf(char(c)));
end
end
end

5 件のコメント

Jan
Jan 2023 年 1 月 17 日
Please explain, what "isn't working" means. You do have this important information already, while the readers have to guess what the problem is.
A bold guess:
if popup_str == 'right'
This works only, if popup_str is a string obejct, e.g. "right" (with double quotes). If it is a char vector, the == operator compares the char vectors elementwise. This must fail, if they have a different number of arguments. You should see a descriptive error message. Use strcmp instead.
Alicja
Alicja 2023 年 1 月 17 日
these are errors I get:
Error using sym/limit
Limit variable must be a symbolic variable.
Error in mat/border (line 39)
c = limit(x, a,'right');
Related documentation
Error while evaluating UIControl Callback.
I don't know how to fix that, I'm at the very beginning of learning MATLAB. Please explain if you can.
Torsten
Torsten 2023 年 1 月 17 日
編集済み: Torsten 2023 年 1 月 17 日
The correct usage of "limit" is
c = limit(f,x,a,'right')
where f is an expression depending on the symbolic variable x, and a can be a numeric value.
Alicja
Alicja 2023 年 1 月 17 日
nothing has changed :/
Torsten
Torsten 2023 年 1 月 17 日
編集済み: Torsten 2023 年 1 月 17 日
You are missing an argument in the call to limit (see above).
And make sure that the first two arguments are of symbolic type (what you can check by the call to "class").

サインインしてコメントする。

回答 (1 件)

Raghav
Raghav 2023 年 4 月 5 日

0 投票

Hi,
Based on your question, I understand that you are facing difficulty using limit function.
The error message suggests that the variable a is not a symbolic variable.
In the border function, you are converting the string input from the hinput_granica edit box to a numeric value using the str2num function. However, limit function from the Symbolic Math Toolbox expects a symbolic variable as the second input, not a numeric value.
To fix the issue, you should create a symbolic variable using the sym function and use it as the second input to the limit function.
The official documentation for limit & sym function is mentioned below respectively:
Hope it helps!
Thanks,
Raghav Bansal

カテゴリ

ヘルプ センター および File ExchangeSymbolic Math Toolbox についてさらに検索

製品

リリース

R2022b

質問済み:

2023 年 1 月 17 日

回答済み:

2023 年 4 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by