i need help with inuptdlg

3 vues (au cours des 30 derniers jours)
Abdelmalek Benaimeur
Abdelmalek Benaimeur le 25 Mar 2019
hello folks
i'm using appdesigner to build an app, i added a push button called save to workspace which allow to the user to save the results to workspace
this is the code i used
prompt = {'Choose the figure name','Choose the Tree name',...
'Choose the Clusters name','Choose the Roots name'};
answer = inputdlg(prompt);
assignin('base',answer{1},app.Figure);
assignin('base',answer{2},app.Tree);
assignin('base',answer{3},app.Clusters);
assignin('base',answer{4},app.Roots);
when i click the pushbutton i obtain this
but the problem is that the user must give a name for all the 4 outputs (results) ,
is there a way to make the user choose the number of the outputs he wants to save

Réponse acceptée

Arvind Sathyanarayanan
Arvind Sathyanarayanan le 25 Mar 2019
Ah! The syntax for inputdlg() is:
answer = inputdlg(prompt,dlgtitle,dims,definput)
The error was because when defining the default input, dlgtitle and dims must also be defined. The correct code is:
prompt = {'Choose the figure name','Choose the Tree name',...
'Choose the Clusters name','Choose the Roots name'};
dlgtitle = 'Input';
dims = 1;
definput={'fig1','tree1','cname','rname'};
answer = inputdlg(prompt,dlgtitle,dims,definput);

Plus de réponses (4)

Arvind Sathyanarayanan
Arvind Sathyanarayanan le 25 Mar 2019
You could specify default values for the 4 inputs. Example:
prompt = {'Choose the figure name','Choose the Tree name',...
'Choose the Clusters name','Choose the Roots name'};
definput={'fig1','tree1','cname','rname'}
inputdlg(prompt,definput)

Abdelmalek Benaimeur
Abdelmalek Benaimeur le 25 Mar 2019
i wrote this
prompt = {'Choose the figure name','Choose the Tree name',...
'Choose the Clusters name','Choose the Roots name'};
definput={'fig1','tree1','cname','rname'};
answer=inputdlg(prompt,definput);
assignin('base',answer{1},app.Figure);
assignin('base',answer{2},app.Tree);
assignin('base',answer{3},app.Clusters);
assignin('base',answer{4},app.Roots);
and i got this:
Error using figure
Value must be a character vector or string scalar.
Error in dialog (line 88)
hDialog = figure('ButtonDownFcn' ,btndown , ...
Error in inputdlg (line 141)
InputFig=dialog( ...
Error in app1111/SaveToWorkspaceButtonPushed (line 553)
answer=inputdlg(prompt,definput);
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.

Abdelmalek Benaimeur
Abdelmalek Benaimeur le 25 Mar 2019
It worked but in this case 4 outputs will be added to the main workspace, My question is in case the user wants to save only one or two outputs what should i do so that the app doesn't return error message
  1 commentaire
Arvind Sathyanarayanan
Arvind Sathyanarayanan le 26 Mar 2019
You could check to see if answer is empty before you send it to the workspace. Example:
prompt = {'Choose the figure name','Choose the Tree name',...
'Choose the Clusters name','Choose the Roots name'};
answer = inputdlg(prompt);
for i=1:4
if ~isempty(answer{i})
evalin('base', 'answer{i}');
end
end

Connectez-vous pour commenter.


Abdelmalek Benaimeur
Abdelmalek Benaimeur le 26 Mar 2019
Modifié(e) : Abdelmalek Benaimeur le 26 Mar 2019
i tried this, but it gave me error it tells me that there is no variable in workspace with this name (answer)
evalin is used to load from Workspace
but you inspired me to find the correct solution, so thank you a lot
this is for my graduation project i will mention your name as a helper.....

Catégories

En savoir plus sur Develop Apps Using App Designer dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by