problem with plotting two uneven data sets

조회 수: 2 (최근 30일)
Viswajit Talluru
Viswajit Talluru 2023년 1월 16일
댓글: dpb 2023년 1월 16일
I have two difcferent data sets that need to be plotted together. I cant crop data from any data set. Couyld som,eone help me with that?

답변 (1개)

Image Analyst
Image Analyst 2023년 1월 16일
Try using hold on
x = linspace(1, 20, 30); % 30 elements.
y = 10 * sin(2 * pi * x / 5) + 5;
plot(x, y, 'b.-', 'MarkerSize', 14, 'LineWidth', 2);
hold on;
grid on;
x2 = linspace(5, 14, 10); % 10 elements
y2 = x2/2;
plot(x2, y2, 'r.-', 'MarkerSize', 14, 'LineWidth', 2);
legend('30 data points', '10 data points', 'Location', 'northwest');
  댓글 수: 1
dpb
dpb 2023년 1월 16일
@Viswajit Talluru-- Alternately to IA's solution, if it were convenient to have the two datasest in the same array, you can always augment the shorter to the length of the longer with NaN -- MATLAB graphics will silently ignore those values when plotting.

댓글을 달려면 로그인하십시오.

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by