필터 지우기
필터 지우기

can I adjusting one vector according to another vector for plotting?

조회 수: 1 (최근 30일)
Hi, I have this matrix for example like this:
Matrix M=
2 4 1 4 6
2 5 NaN 8 1
4 NaN 9 NaN NaN
9 6 NaN NaN 7
And vector T=
1
2
3
4
I am trying to plot vector T on the x-axis with every row column of matrix M on the y-axis. This works fine the plot aoutoatically ignore the points with NaN.
The problem is I would also like to use polyfit, to get a fitting equation. But Polyfit is does not skip NaN values, which gives only NaN as coefficients. Please note that I the matrix M is orignally a much larger matrix same as vector T is much larger. These are just examples for my point.
My question is is there a another way to get the equation of a fitted line fo every coumn vs vector T.
Example, the option in the graph tools> basic fitting works great, but this is manual. I need to output the fitting equations for large matriceis in a for loop and store them.

채택된 답변

Matt J
Matt J 2024년 1월 23일
Given x,y for fitting,
I=~isnan(x)&~isnan(y);
p=polyfit(x(I), y(I),1)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interpolation에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by