How to draw a line of best fit on filtered discrete data sets
古いコメントを表示
How can i draw a line of best fit on a subset of the full data set?
I want a line of best fit but only using the data in blue below
So ignore the green, yellow, orange, red, only use the blue part
Now that is easily filtered down to, so know which parts are the blue part is easy, but getting to somehow draw a line of best fit to only use the blue is the challeging part

I can filter the data set to only show the data i want to use for the line of best fit, as shown in graph below

Now all i need it to find a way to draw a line of best fit on this data set, but when i try polyfit and other best fit functions, it gets all messed up
I'm assuming because of the gaps in the dataset.
So how can i draw a line of best fit for the chart above?
5 件のコメント
Mathieu NOE
2021 年 6 月 4 日
hello
so the gaps correspond of some data exceeding a given threshold ... did you simply remove the data or you replaced it with NaN's ?
polyfit cannot work with data containing NaN's - they must be removed , this is one trick :
If the NaNs occur in the same locations in both the X and Y matrices, you can use a function call like the following, your_function( X(~isnan(X)), Y(~isnan(X)) ). If the NaNs don't occur in the same locations, you will have to first find the valid indices by something like, `X(~isnan(X)| isnan(Y))'
Scott MacKenzie
2021 年 6 月 4 日
Please provide the data
Rizwan Khan
2021 年 6 月 4 日
Rizwan Khan
2021 年 6 月 4 日
Scott MacKenzie
2021 年 6 月 4 日
You post data via the Attachments button when you are writing your question:

If you insert code in your question, it's always best to have it properly appear as code. To do this, select the code and click the code button to get the code propertly formatted in your question.

採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Get Started with Curve Fitting Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



