Asked by Marie Robert
on 24 Apr 2018

Hello everyone,

I am currently trying to figure out a way to create a curve that would fit my data, not using the "plot" function. I have seen that there are filters that exist and tried the "sgolay" one but it won't work (probably because I don't quite understand how it works). I would appreciate some help.

Here is the current code:

set(0,'defaulttextinterpreter','latex') clf %plot(alpha1,F_z1,'*') hold on barplotxy(alpha1,F_z1,lalpha1,delta_fz1); barplotxy(alpha2,F_z2,lalpha2,delta_fz2); barplotxy(alpha3,F_z3,lalpha3,delta_fz3); barplotxy(alpha4,F_z4,lalpha4,delta_fz4); h=sgolayfilt(alpha4, 4, 7) title('Variation de la portance $F_z$ en fonction de l''angle d''incidence $\alpha$') ylabel('Force $F_z$ de portance [N]'); xlabel('Angle d''incidence $\alpha$ de l''\''ecoulement [rad]'); axis([-0.5 1 0 1.62])

and the previous version of the graph:

The smooth curve would fit the blue data (instead of a linear fit).

PS: I am French and I struggle with very specific terms (and Matlab in general) so it would d be really nice if you used the simplest terms possible.

Answer by Stephan Jung
on 24 Apr 2018

Edited by Stephan Jung
on 24 Apr 2018

Accepted Answer

Hi,

thats nice so far. You did it with the curve fitting toolbox i guess (?)

Try the xlim command after the plot command for your fitted curve:

xlim([-0.5,1])

The interval of -0.5...1 is just taken from your diagramm - you can of course use the variables of your .mat files data for adjusting this.

I hope it works well for you. If you still have problems please share your code.

best regards

Stephan

Marie Robert
on 24 Apr 2018

At last, I did succeed at doing what I wanted to do. Thank you very much for your help!

Stephan Jung
on 24 Apr 2018

c'était un plaisir!

Kh zaa
on 16 Sep 2018 at 19:04

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Stephan Jung (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/397111-how-can-i-create-a-smooth-curve-that-fits-my-data#comment_560476

Hi,

can you append your .mat files to your question please.

best regards

Stephan

## Marie Robert (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/397111-how-can-i-create-a-smooth-curve-that-fits-my-data#comment_560478

Sure, here it is

## Stephan Jung (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/397111-how-can-i-create-a-smooth-curve-that-fits-my-data#comment_560483

Si vous avez la boîte à outils d'ajustement de courbe, utilisez-la.

Si ce n'est pas le cas, ce lien peut vous aider ici. Vous pouvez également faire traduire la documentation de Matlab en français - cela fonctionne plutôt bien. Cliquez sur le bouton "Traduire cette page" dans le coin supérieur droit et sélectionnez la langue appropriée. Dans votre cas probablement français ;-)

En attendant, je vais regarder vos données.

Bonne chance Si vous avez d'autres questions, s'il vous plaît contactez-nous.

Salutations Stephan

## Marie Robert (view profile)

Direct link to this comment:https://www.mathworks.com/matlabcentral/answers/397111-how-can-i-create-a-smooth-curve-that-fits-my-data#comment_560496

Thank you for your help! I did succeed at fitting my data. However, I have a new problem: when I plot the fittedmodel ( plot(fittedmodel1,F_z4,alpha4) ), a part of it is cropped in my figure window. How can I solve this ?

Sign in to comment.