How can I make a single plot that consists of multiple lines, each made from every n rows of a vector?
2 次查看(过去 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.
0 个评论
采纳的回答
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 Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!