How to create a loop for a matrix and plot the outputs in a graph?

I have a matrix that is called merged, the matrix is 100 x 2. I want to create a loop that breaks down the matrix into 5 small matrices (20 x 2) and I want to draw these matrices in one figure. I have done that using the below commands but I wonder if I can do that using a loop?
x = merged (1:100,1:2); a = x (1:20,:); b = x (21:40,:); c = x (41:60,:); d = x (61:80,:); e = x (81:100,:); hold on plot (a(:,1),a(:,2)) plot (b(:,1),b(:,2)) plot (c(:,1),c(:,2)) plot (d(:,1),d(:,2)) plot (e(:,1),e(:,2))

 채택된 답변

Jan
Jan 2018년 10월 18일
편집: Jan 2018년 10월 18일
x = rand(100, 2);
axes('NextPlot', 'add'); % equivalent to "hold on"
for k = 1:5
a = (k - 1) * 20 + 1;
b = a + 19;
plot(x(a:b, 1), x(a:b, 2));
end
Or
for k = 1:20:100
plot(x(k:k+19, 1), x(k:k+19, 2));
end

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Objects에 대해 자세히 알아보기

태그

질문:

2018년 10월 17일

편집:

Jan
2018년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by