How can I make a single plot that consists of multiple lines, each made from every n rows of a vector?

조회 수: 5 (최근 30일)
I have looked everywhere and I can't seem to find anything for this. All I can find is how to plot every nth row, but I need to make a line for every n rows of a 2-column vector and overlay them all on the same graph. My data is very large so here is a simple example (assume col. 1 is x-data and col.2 is y-data):
A = [ 1 2
2 4
3 6
4 8
5 10
6 12 ]
I want a single plot that consists of two lines (in this case). The first being rows 1-3, where x1 = [1 2 3] and y1 = [2 4 6], and the second being rows 4-6, where x2 = [4 5 6] and y2 = [8 10 12].
I feel like this should be simple but I cannot seem to do it properly and the answers online are usually for every nth row, and not for what I need. Also, since I have large data, I'm sure I will need to use a loop because I won't be able to do this manually for a 300,000 x 2 set of data.

채택된 답변

Stephen23
Stephen23 2019년 7월 10일
편집: Stephen23 2019년 7월 10일
"I'm sure I will need to use a loop because I won't be able to do this manually for a 300,000 x 2 set of data."
I don't see why you would need to use a loop. Most likely using a loop would not be an effective use of MATLAB.
>> A = [1,2;2,4;3,6;4,8;5,10;6,12]
A =
1 2
2 4
3 6
4 8
5 10
6 12
>> n = 3;
>> X = reshape(A(:,1),n,[]);
>> Y = reshape(A(:,2),n,[]);
>> plot(X,Y,'*-')

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by