MATLAB Answers

Tying a specific amount of variable to a specific amount of edit boxes

1 view (last 30 days)
Seth Newton
Seth Newton on 20 Apr 2017
Answered: Chaitral Date on 25 Apr 2017
I am attempting to create a GUI in which the user uses drop down menus to select a specific subject, and then a specific equation. What I'm attempting to do is have the GUI request the givens of said problem, and then the user would input the givens and it would solve the equation. If I have n variables for givens, is there any way I could make the GUI display n amount edit boxes for any equation the user asks for?

Answers (1)

Chaitral Date
Chaitral Date on 25 Apr 2017
I roughly understood your requirement. Can you please elaborate it in more detail? What do you exactly mean by givens? From what I can analyze after reading your description is, you want to have a drop drown menu to select specific equation. Depending upon the equation selected, if the equation has n variables, then the GUI should display n edit boxes. Here is what you can do,
popup = uicontrol('Style', 'popup',...
'String', {'x+y=z','b+c/r=a'},...
'Position', [20 340 100 50],...
'Callback',@setvar);
function setvar(hobj,~)
equation=cell2mat(hobj.String(hobj.Value));
vars=symvar(equation);
for k=1:length(vars)
editbox(k)=uicontrol('Style','edit','Position', [20*k^2 300 50 20]);
text(k)=uicontrol('Style','text','Position', [20*k^2 250 50 20],'String',vars{k});
end
editbox(1).Callback={@foo};
end
function foo(hobj,~)
end
This is just an example of what you can do. You can further modify the above code as per your requirement. I hope this helps. If not, then please let me know your requirement in more detail.

Tags

Community Treasure Hunt

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

Start Hunting!