From: Quy Phan on
I would like to display the inputted string for the variable instead of the values that are computed for that variable. Is there a way to do this? My code is below:

%%
%input parameters
n=input('enter length of time vector, (n): ');
f=input('enter signal, with (n) as independent variable; (f): ');

%to show input parameters
n, f,
%%

When prompted, I enter "0:10" for n, and "cos(n)" for f, and this is what is displayed on the command window:
n =
0 1 2 3 4 5 6 7 8 9 10
f =
Columns 1 through 8
1.0000 0.5403 -0.4161 -0.9900 -0.6536 0.2837 0.9602 0.7539
Columns 9 through 11
-0.1455 -0.9111 -0.8391

Instead, I want to display on the command window the following:

n = 0:10
f = cos(n)

I tried using 's' within the input, but that does not calculate the values, and I do want it to calculate the values. Ultimately, I want to suppress the evaluations (the answer), and only show the inputted "text."

Is this possible to do?
From: Walter Roberson on
Quy Phan wrote:
> I would like to display the inputted string for the variable instead of
> the values that are computed for that variable. Is there a way to do
> this?

Possibly with inputname()
From: Walter Roberson on
Quy Phan wrote:
> n = 0:10
> f = cos(n)
>
> I tried using 's' within the input, but that does not calculate the
> values, and I do want it to calculate the values.

Sorry, didn't read the posting carefully enough.

There is no documented way to have input() evaluate a user-provided expression
and have it return both the values and the literal string provided by the user.

If you want to be display the string entered by the user, use input with the
's' option; when you need the value implied by the string, eval() the string
and hope the user didn't enter the string '!rm *'
From: Quy Phan on
Walter Roberson <roberson(a)hushmail.com> wrote in message
> Sorry, didn't read the posting carefully enough.
>
> There is no documented way to have input() evaluate a user-provided expression
> and have it return both the values and the literal string provided by the user.
>
> If you want to be display the string entered by the user, use input with the
> 's' option; when you need the value implied by the string, eval() the string
> and hope the user didn't enter the string '!rm *'

I tried 's' within the input(), and then evaluate using eval(), and then suppressing the eval() following the guideline from http://www.mathworks.nl/matlabcentral/newsreader/view_thread/137363, but I was unsuccessful. Here is my code:

%%
n=input('enter length of time vector, (n): ','s');
f=input('enter signal, with (n) as independent variable; (f): ','s');

f, n

n=eval([ '[' n '];' ]);
f=eval([ '[' f '];' ]);
%%

a couple of the quotations in the above eval() seems unnecessary, but I tried it anyway just to be sure. The command window still display the calculated values, which I want to suppress.

I think I am stuck with what I got.

Thank you.
From: Matt Fig on
This works:


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [] = disp_inputs

diary('disp_inputs_dat.txt')
n = input('enter length of time vector, (n): ');
f = input('enter signal, with (n) as independent variable; (f): ');
diary off

F = fopen('disp_inputs_dat.txt');
STR = textscan(F,'%s');
fclose(F);
delete disp_inputs_dat.txt

sprintf('\n\t You entered %s for n and %s for f \n',STR{1}{7},STR{1}{end})
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Now at the command line:

>> disp_inputs
enter length of time vector, (n): 0:.1:5
enter signal, with (n) as independent variable; (f): cos(n)
ans =

You entered 0:.1:5 for n and cos(n) for f

>> disp_inputs
enter length of time vector, (n): 1:4
enter signal, with (n) as independent variable; (f): sin(n)
ans =

You entered 1:4 for n and sin(n) for f