how to plot curved fitting but the value of x and y must be key in by the user at the command window.

2 visualizaciones (últimos 30 días)
this is the programing that i had done and the output that i want.
x=[249 191 150 139 130 123]';
y=[20 40 60 80 100 120]';
cftool(x,y);
fitresult = fit(x,y,'exp2'); figure; subplot(111), plot(fitresult,x,y); xlabel('distance(pixels)') ; ylabel('molecular weight(mer)');grid;
my problem is,the value x and y must be key in at the command window. so i write another program.this my program..
x= input ('x? '); y=input ('y? ');
cftool(x,y);
fitresult = fit(x,y,'exp2'); figure; subplot(111), plot(fitresult,x,y); xlabel('distance(pixels)') ; ylabel('molecular weight(mer)');grid;
but when i key in the value x and y at the command window,i cannot get the output. can u help me to solve this problem.

Respuestas (1)

Geoff
Geoff el 2 de Mayo de 2012
Do you mean that you are experiencing this:
> x = input('x? ')
x? 249 191 150 139 130 123
249 191 150 139 130 123
|
Error: Unexpected MATLAB expression.
Unless you tell it not to, the input command evaluates what you type in as a MatLab expression. You could do this:
> x = input('x? ', 's')
x? [249 191 150 139 130 123]
x =
[249 191 150 139 130 123]
But I would never do that, even if I am the only one who would use the program. I don't like programs that can execute arbitrary commands typed in by the user. Instead, I would read the input as a string and then extract the numbers from it as follows:
> x = sscanf( input('x? ', 's'), '%d' )
x? 249 191 150 139 130 123
x =
249
191
150
139
130
123
The above code only accepts integers. If you wanted to allow doubles, use the '%f' format instead:
x = sscanf( input('x? ', 's'), '%f' );

Categorías

Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by