Effacer les filtres
Effacer les filtres

Define a variable via inputdlg?

4 vues (au cours des 30 derniers jours)
Mark
Mark le 30 Jan 2014
Commenté : Mark le 31 Jan 2014
I would like a variable to be assigned via a user prompt. For example, consider the following command:
row = inputdlg('Insert row number.');
When a user inputs 1 in the popup box, the value of the variable "row" is not recognized as a number or a string, but as a '1', with ticks surrounding it.
Is there a way to have a variable defined as a number or a string from a popup box?
Thank you!

Réponse acceptée

Amit
Amit le 30 Jan 2014
row = inputdlg('Insert row number.');
row = str2num(row{:});
  3 commentaires
Amit
Amit le 30 Jan 2014
That's correct and that's what this will do (give it a try). You can replace row with whatever variable name you like.
Moreover, row is not a matlab command that you'll override by using as a variable !
Mark
Mark le 31 Jan 2014
Thank you! Works like a charm :)

Connectez-vous pour commenter.

Plus de réponses (1)

David Sanchez
David Sanchez le 30 Jan 2014
You can do it in a single line and use str2double which is faster than str2num:
row = str2double( inputdlg('Insert row number.') );
  1 commentaire
Mark
Mark le 31 Jan 2014
Excellent! Problem solved, thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Cell Arrays dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by