2016-07-15 54 views
1

我需要绘制与在Matlab以下格式的单元阵列:绘制单元阵列

{[vector1], [vector2], ...} 

成2D图形用所述载体作为y的索引和矢量为x

([vector1], 1), ([vector2], 2), ... 
+2

你真的可以给我们一些真实的数据,以便我们看到你在说什么吗?你的解释不是很清楚。 – Suever

+0

因此,每个_y_值都有一个_x_值的关联_vector_?那个怎么样? –

回答

2

这里有一个简单的选择:

% some arbitrary data: 
CellData = {rand(10,1)*50,rand(10,1)*50,rand(10,1)*50}; 

% Define x and y: 
x = cell2mat(CellData); 
y = ones(size(x,1),1)*(1:size(x,2)); 

% plot: 
plot(x,y,'o') 
ylim([0 size(x,2)+1]) 

所以您绘制的x每个向量在一个单独的y值:

A cell plot

它将工作只要你的单元阵列只是一个向量列表。

编辑:对于非平等的载体

你必须使用一个for循环与hold

% some arbitrary data: 
CellData = {rand(5,1)*50,rand(6,1)*50,rand(7,1)*50,rand(8,1)*50,rand(9,1)*50}; 

figure; 
hold on 
for ii = 1:length(CellData) 
    x = CellData{ii}; 
    y = ones(size(x,1),1)*ii; 
    plot(x,y,'o') 
end 
ylim([0 ii+1]) 
hold off 

Cell plot 2

希望这回答你的问题;)

+0

我的向量是不同的大小,所以cell2mat(Celldata)不起作用 – user3743825

+0

@ user3743825看到我编辑的答案 – EBH

0

没有任何数据,这是我能想出的最好的,你想要什么:

yourCell = {[0,0,0],[1,1,1],[2,2,2]}; % 1x3 cell 
figure; 
plot(cell2mat(yourCell)); 
ylabel('Vector Values'); 
xlabel('Index of Vector'); 

它使这样一个情节:

enter image description here

希望这有助于。

+0

为什么你换了'x'和'y'轴?他希望矢量索引是一个'y'轴。 – EBH

+0

@EBH我想我一定把这个问题和另一个问题搞混了,哎呀。我改变了我的答案。抱歉。 – user3716193

1

这是我的(蛮力)解释你的请求。有可能更优雅的解决方案。

此代码会生成一个点图,将来自y轴—上每个索引处的向量的值放在最下面。它可以适应不同长度的载体。您可以将其作为矢量分布的点图,但如果可能出现多个相同或几乎相同的值,则可能需要向x值添加一些抖动。

% random data--three vectors from range 1:10 of different lengths 
for i = 1:3 
    dataVals{i} = randi(10,randi(10,1),1); 
end 

dotSize = 14; 
% plot the first vector with dots and increase the dot size 
% I happen to like filled circles for this, and this is how I do it. 
h = plot(dataVals{1}, ones(length(dataVals{1}), 1),'.r'); 
set(h,'markers', dotSize); 

ax = gca; 
axis([0 11 0 4]); % set axis limits 
% set the Y axis labels to whole numbers 
ax.YTickLabel = {'','','1','','2','','3','','',}'; 

hold on; 
% plot the rest of the vectors 
for i=2:length(dataVals) 
    h = plot(dataVals{i}, ones(length(dataVals{i}),1)*i,'.r'); 
    set(h, 'markers', dotSize); 
end 
hold off 

enter image description here