I have two arrays:
1_time ->
t=(0:15);
2_measurements ->
data1=[ 0 7 20 28 35 48 57 61 72 82 96 98 111 121 129 144 ];
I have to get the estimation at t=20 ( linear method ) ,and the 'minimum & maximum' difference between the linear equation line and the data1 curve .
My method was :
1 Making a plot ->
plot(t,data1);
2 Getting the estimated at t=20 by using the numerical panel (tool-> basic fitting)
3 And finally i get the 'minimum & maximum' difference between the linear equation line and the data1 curve , by plotting the residuals
Is there any code to get what i want and not by using plotting .. ect ? I am a newbie when it come to matlab

댓글 수: 2

Image Analyst
Image Analyst 2016년 4월 20일
This is a 1-D curve, not a 2-D curve. For each element of your dependent variable, "data1", there is exactly one independent variable, "t", that specifies it, not two. data1 is a 1-D vector, not a 2-D matrix.
MRT gang
MRT gang 2016년 4월 21일
Question is updated ! thank you .

댓글을 달려면 로그인하십시오.

 채택된 답변

Star Strider
Star Strider 2016년 4월 20일

0 개 추천

If you are confident of a linear fit, just calculate the extrapolated ‘data1’ value at ‘t=20’:
t=(0:15);
data1=[ 0 7 20 28 35 48 57 61 72 82 96 98 111 121 129 144 ];
B = [t' ones(size(t'))]\data1'; % Estimate Coefficient Of Linear Fit
data1_fit = [t' ones(size(t'))]*B; % Create Regression Line To Plot
data1_20 = [20 1]*B % Extrapolate Fit To ‘t=20’
figure(1)
plot(t, data1, 'bp')
hold on
plot(t, data1_fit, '-g')
plot(20, data1_20, '*r')
hold off
grid
axis([0 21 -10 200])
This code plots the data and fit using the mldivide,\ operator, and plots and calculates the extrapolated value:
data1_20 =
186.43

댓글 수: 4

MRT gang
MRT gang 2016년 4월 21일
편집: MRT gang 2016년 4월 21일
Really appreciate your help . Any idea about the second half of what i wanted ? thanks
Star Strider
Star Strider 2016년 4월 21일
My pleasure.
I believe I did both. The plot is figure(1), and the extrapolation is this line:
data1_20 = [20 1]*B % Extrapolate Fit To ‘t=20’
producing:
data1_20 =
186.43
I didn’t see part 3. about the residuals and residual plot until I went looking for it just now. Add this to the end of my previous code, and I believe we’ve covered everything:
resid = data1 - data1_fit';
resid_extr = [min(resid) max(resid); min(abs(resid)) max(abs(resid))];
logc_vct = [abs(resid) == resid_extr(2,1); abs(resid) == resid_extr(2,2)];
figure(2)
stem(t, resid)
hold on
plot(t(logc_vct(1,:)), abs(resid(logc_vct(1,:))), '*r', t(logc_vct(2,:)), abs(resid(logc_vct(2,:))), '*r')
hold off
grid
xlabel('Time')
ylabel('Residual')
axis([-1 16 ylim])
The ‘resid_extr’ matrix are the minima and maxima of the residuals and the absolute values of the residuals. I plotted all and highlighted the minimum and maximum absolute values. I used logical vectors rather than the find function in the ‘logc_vct’ array, just for variety. It doesn’t make any difference in the behaviour of the code.
MRT gang
MRT gang 2016년 4월 29일
thank you very much ! i appreciate your help
Star Strider
Star Strider 2016년 4월 29일
My pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2016년 4월 20일

0 개 추천

out=interp1(t,data1,20,'linear','extrap')

댓글 수: 1

MRT gang
MRT gang 2016년 4월 20일
the result is not the same when using my method ( plot->basic fitting>numerical estimation )

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Fit Postprocessing에 대해 자세히 알아보기

태그

질문:

2016년 4월 20일

댓글:

2016년 4월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by