2 simultaneous curve fits on the same plot

조회 수: 1 (최근 30일)
Sai Gudlur
Sai Gudlur 2018년 12월 13일
답변: Sai Gudlur 2018년 12월 13일
Hello Everyone,
The motive of this code is to find delta of the Angle (Y-Axis). On the X- Axis the Torque Ranges from -x to +x. I want to fit two curve fit lines one when Torque >=0 and other one Torque<=0 on the same plot. Could someone help? I have attached my code and also the figure with lines how i intend to have my figure. Any suggestion or help is appreciated.
Thanks
Anand
[filename,pathname] = uigetfile('*.txt');
fullfilename = fullfile(pathname,filename);
A = importdata(fullfilename);
Torque=A(:,1);
Angle=A(:,2);
xmin=min(Torque);
xmax=max(Torque);
ymin=min(Angle);
ymax=max(Angle);
yavg=mean(Angle);
xavg=xmax;
id = (Torque >= 0);
Torque_Positive = Torque(id);
Angle_Positive = Angle(id);
it = (Torque <=0);
Torque_Negative = Torque(it);
Angle_Negative = Torque(it);
T1 = table(Torque_Positive,Angle_Positive);
T2 = table(Torque_Negative,Angle_Negative);

답변 (1개)

Sai Gudlur
Sai Gudlur 2018년 12월 13일
Hello Everyone,
Got it. Have attached my code below. If some one could suggest a even more efficient way i would be more than happy to learn.
[filename,pathname] = uigetfile('*.txt');
fullfilename = fullfile(pathname,filename);
A = importdata(fullfilename);
Torque = A(:,1);
Angle = A(:,2);
plot(Torque,Angle)
Torque_min = min(Torque);
Torque_max = max(Torque);
Torque_avg = mean(Torque);
Angle_min = min(Angle);
Angle_max = max(Angle);
Angle_avg = mean(Angle);
Torque=A(:,1);
Angle=A(:,2);
figure;
hold on
plot(Torque,Angle);
xmin=min(Torque);
xmax=max(Torque);
ymin=min(Angle);
ymax=max(Angle);
yavg=mean(Angle);
xavg=xmax;
dtq=diff(Torque);
i=find(dtq<0);
Torque=Torque(i);
Angle=Angle(i);
id = (Torque >= 0);
Torque_Positive = Torque(id);
Angle_Positive = Angle(id);
it = (Torque <=0);
Torque_Negative = Torque(it);
Angle_Negative = Torque(it);
p1 = polyfit(Torque_Positive,Angle_Positive,2);
p2 = polyfit(Torque_Negative,Angle_Negative,2);
plot(Torque_Positive,polyval(p1,Torque_Positive));
hold on
plot(Torque_Negative,polyval(p2,Torque_Negative));

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by