Is there a better way to plot an array?

时间:2019-04-17 01:01:48

标签: matlab plot

I would please like to know, if there is a better way to plot a nx2 matrix

This is how I do:

%... matrix
 A = [2 4 2 6 8; 9 8 7 6 4];

 %plot
 column1 = A(:,1);
 column2 = A(:,2);
 plot(column1, column2, 'r+')
  1. Is there a possibility like for example:
 plot(A, 'r+') %???

Why does this not work?

I also can't get how this work
 plot(A, 'r+') %???

I expect, that each row consists of x and y coordinate respectively. Thank you in advance

2 个答案:

答案 0 :(得分:0)

Your question suggests that the array should be plotted so that the first row is x and the second row is y, but the format of your code indicates that you were trying to plot them by columns instead.

Try the following code and, if it doesn't produce the desired plot, please be more specific with your question.

A = [2 4 2 6 8; 9 8 7 6 4];
x_row = A(1,:);
y_row = A(2,:);
plot(x_row,y_row)

If you want to change this from a line plot to a dot plot, simply include that in the end of your plot statement as you'd done so previously.

e.g.,

plot(x_row,y_row, 'go')

答案 1 :(得分:0)

是的,此功能存在。

如果您将免费的Matlog toolbox用于物流工程,则代码将为pplot(A,'r+')-请参见pplot的第一个示例。

A = [2 4 2 6 8; 9 8 7 6 4].';
pplot(A,'r+')

您可以像平常一样调整属性。

p = pplot(A,'r+');
p.MarkerSize = 12;     % Adjust marker size 

这是更好的方法吗??我不知道。那要看。有时确实会派上用场,尤其是当您在 nx2 数组中有坐标数据时。


Matlog toolbox是由NC State University的Professor Michael Kay编写和维护的物流工程免费工具箱。它会定期接收更新。

我经常在某些应用程序中使用它(它具有几个高实用功能)。有趣的是,我发现它与MATLAB R2018b及更早版本兼容。

  

该工具箱包含用于解决以下类型的问题的功能   问题:

     

设施位置:连续的最小设施位置,备用位置分配(ALA)程序,离散的无能力设施   位置
  货运: TL和LTL的运输费用,总物流成本,总计多次装运
  车辆路线:VRP,带时间窗的VRP,旅行商问题(TSP)
  网络:最短路径,最小网络流量,最小生成树问题
  地理编码:将美国城市或邮政编码转换为经度和纬度,将经度和纬度转换为最近的城市,墨卡托投影图
  布局: QAP的最速下降成对互换(SDPI)启发式方法
  通用:使用修订后的单纯形方法过程进行线性编程,混合整数线性编程和Cplex
  与MILP接口
  数据:人口至少为10,000的美国城市,美国公路网(橡树岭国家公路网);美国3和   5位邮递区号;美国人口普查阻止小组数据

来源:Matlog documentation