0

I'm trying to ask the user for a value of some variable, but at the same time, showing him the last value used (at the termination of the program, the values are saved to a file, and loaded at the start of the program).

Something like this:

Enter new radius value (R=12.6) :
... user enters 12.7 ...
Enter new pi value (pi=3.14) :
Enter new height value (h=30.0) :

Usually I would write the first one with write statement, then read the new one (in Fortran, for example). In MATLAB however, I don't know how to write something out with input statement. Are there some other statements for getting input ?

2
  • @MatlabDoug - MATLAB is okey, my mistake there, but fortran is no longer an acronym, but a name, and it is written in lowercase. Commented May 11, 2010 at 1:19
  • 1
    @Idigas So it is: en.wikipedia.org/wiki/Fortran#cite_note-0 Guess that shows that when I last used Fortran it was FORTRAN 77! :) Commented May 11, 2010 at 13:44

1 Answer 1

5

You can use the command input for this, combined with sprintf.

%# set defaults
radius = 12.6;

%# ask for inputs
tmp = input(sprintf('Enter new radius value (R=%4.2f)\n',radius));
%# if the user hits 'return' without writing anything, tmp is empty and the default is used
if ~isempty(tmp)
    radius = tmp;
end

As an alternative, you may want to look into INPUTDLG

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.