trouble with basic plotting,

조회 수: 3 (최근 30일)
Dan
Dan 2011년 7월 18일
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