Plotting Matrix points
7 次查看(过去 30 天)
显示 更早的评论
Hello everyone!
I have a 2 by 10 matrix:
B =
28.7636 27.7497
26.7351 25.7208
23.6934 22.6793
20.6512 19.6371
18.6241 17.6092
15.5820 14.5679
13.5537 11.5246
10.5116 9.4974
8.4835 6.4551
5.4414 4.4273
I am trying to figure out how to plot these matrix points in pairs:
28.7636 27.7497 % start of first point and end of first point
26.7351 25.7208 % start of 2nd point and end of 2nd point
And so on...
I haven't been able to determine the correct plot syntax to accomplish this. Matlab has so many commands when it comes to plotting I dont even know where to start!
Thank in advance!
5 个评论
采纳的回答
Walter Roberson
2011-7-19
If you do not want to loop over line(B(K,1),B(K,2)) then you can use this trick:
X = reshape(B(:,1),2,[]);
X(3,:) = nan;
X = X(:);
Y = reshape(B(:,2),2,[]);
Y(3,:) = nan;
Y = Y(:);
plot(X,Y)
This introduces a nan after every second point, and then zips everything back together. nan are treated as indicating a break in plotting.
Jan, I think it was, pointed out to me that inf could be used in place of nan for this purpose, and that most modern cpus handle inf more quickly than they handle nan.
5 个评论
更多回答(4 个)
Fangjun Jiang
2011-7-19
Not enough information. Your B is 10x2 matrix, not 2x10. Maybe:
a=[1:10;1:10];
line(a,B');
Horizontal lines:
line(B',zeros(2,10));
hold on;
plot(B,zeros(10,2),'o');
Vertical lines:
line(zeros(2,10),B');
hold on;
plot(zeros(10,2),B,'o');
7 个评论
Fangjun Jiang
2011-7-20
Should the start time be less than the stop time? Maybe it doesn't matter. Should horizontal lines be more suitable than vertical lines since they indicate time lapse? Anyway, see edit in my answer for both options.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Annotations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!