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 Center および File ExchangeGet 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