so here is my matlab code, and the problem is there is repeated x values and spline fit code doesn't work how can i make it so it only takes the first x and doesn't take the repeated ones? And im not good at matlab so, can you please show how to add the code or add it to the original code.
load Pvst1.txt
load Fvst1.txt
tx = Pvst1(:,1);
tF = Fvst1(:,1);
x = Pvst1(:,2);
F = Fvst1(:,2);
tq=0:0.01:5.81;
Fq = interp1(tF,F,tq,'spline');
xq = interp1(tx,x,tq,'spline');
plot(xq,Fq,'ko');
hold on
xlabel('Position (m)','Fontsize',24)
ylabel('Force (N)','Fontsize',24)
title('Force vs. Position for car, Part A','Fontsize',24)
grid on
hold on

 採用された回答

Torsten
Torsten 2015 年 12 月 9 日
編集済み: Torsten 2015 年 12 月 9 日

1 投票

tx and tF must be monotonically increasing without repeating values, but this is the case for your data. The x and F arrays do not matter. So everything should be o.k. for spline interpolation.
Do you get an error message ?
Replacing
tq=0:0.01:5.81;
by
tq=max(tx(1),tF(1)):0.01:min(tx(end),tF(end));
might help.
Best wishes
Torsten.

6 件のコメント

Olca Orakci
Olca Orakci 2015 年 12 月 9 日
when i press run i doesn't give any error but there is no spline fit in the graph, when i try to add it from tools it gives an error saying there is multiple x values.
Torsten
Torsten 2015 年 12 月 9 日
The spline fit is done when you calculate xq and Fq.
You shouldn't request a spline for the plotting of Fq vs. xq.
Best wishes
Torsten.
Olca Orakci
Olca Orakci 2015 年 12 月 9 日
i know, but shouldn't spline fit connect the dots?
Torsten
Torsten 2015 年 12 月 9 日
If you choose
plot(xq,Fq,'-ok')
the points are automatically connected by a solid line :-)
Best wishes
Torsten.
Olca Orakci
Olca Orakci 2015 年 12 月 9 日
Nice, thanks for the help, and have a good day sir.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeSpline Postprocessing についてさらに検索

質問済み:

2015 年 12 月 9 日

コメント済み:

2019 年 7 月 23 日

Community Treasure Hunt

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

Start Hunting!

Translated by