trouble with basic plotting,

3 次查看(过去 30 天)
Hello,
I have recently been using matlab and learning its workings as I go, I am fairly new to the program. I am working on generating a best fit curve and have used the basic fitting tool and am trying to plot the cubic fit function in my program. I am not sure why it will not plot.
I wrote
dt=4E-9; % Time Step L=9999; % Length t=(0:L-1)*dt; % Time array by steps of dt x= (0:L-1)*(1/dt); yfit = 4.5e-021*x^3 - 9.9e-015*x^2 + 5.5e-009*x - 3.1e-005; plot(x,yfit,'g')
the error it gives me is
??? Error using ==> mpower Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead.
Error in ==> Spectrum1210702793 at 79 yfit = 4.5e-021*x^3 - 9.9e-015*x^2 + 5.5e-009*x - 3.1e-005;
Also is there a way to generate code to copy into my m file from using the basic fitting tool.
Can you help me, thanks,
Dan

采纳的回答

Sean de Wolski
Sean de Wolski 2011-7-18
??? Error using ==> mpower Inputs must be a scalar and a square matrix. To compute elementwise POWER, use POWER (.^) instead.
This issue and solution is right there in the error message. You're trying to do a matrix power (linear algebra) when you really want an element-by-element power. The solution - put a '.' before every power.
yfit = 4.5e-021*x.^3 - 9.9e-015*x.^2 + 5.5e-009*x - 3.1e-005;

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear and Nonlinear Regression 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by