trouble with basic plotting,

5 vues (au cours des 30 derniers jours)
Dan
Dan le 18 Juil 2011
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

Réponse acceptée

Sean de Wolski
Sean de Wolski le 18 Juil 2011
??? 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;

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by