필터 지우기
필터 지우기

How to approximate a curve in a matrix?

조회 수: 3 (최근 30일)
Glypton
Glypton 2022년 6월 19일
답변: Ishaan Mehta 2022년 6월 25일
Hello everyone,
I want to find a curve which fits in the following way for the whole width of the matrix but I really have no idea of how to do this. I tried to rotate the matrix by 180 degree and apply a mask but it is just not working. You can find a part of the matrix attached to this post.

채택된 답변

Ishaan Mehta
Ishaan Mehta 2022년 6월 25일
Hi Glypton
I understand that you want to plot the maximum values of each row in the matrix, over a plot of the matrix itself.
This can be done using MATLAB's plot function and max function.
Here is a code snippet for the same, applied on the matrix file you have attached.
plot(matrix);
maxVals = max(matrix, [], 2);
hold on
plot(maxVals, "r", "LineWidth",2);
hold off
This is the output plot generated:
If you wish to fit a smoother curve as an approximation for the data, you can use the smooth function.
plot(matrix);
maxVals = max(matrix, [], 2);
smoothMaxVals = smooth(double(maxVals));
hold on
plot(smoothMaxVals, "r", "LineWidth",2);
hold off
This is the output plot generated:
Hope it helps
Ishaan

추가 답변 (0개)

카테고리

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

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by