Matlab 绘制单元阵列

Matlab 绘制单元阵列,matlab,plot,matlab-figure,scatter-plot,cell-array,Matlab,Plot,Matlab Figure,Scatter Plot,Cell Array,我需要在Matlab中用以下格式绘制一个单元格数组: {[vector1], [vector2], ...} 转化为一个二维图形,其中向量的索引为y,向量的索引为x ([vector1], 1), ([vector2], 2), ... 在没有任何数据的情况下,这是我能为您提供的最佳解决方案: yourCell = {[0,0,0],[1,1,1],[2,2,2]}; % 1x3 cell figure; plot(cell2mat(yourCell)); ylabel('Vector V

我需要在Matlab中用以下格式绘制一个单元格数组:

{[vector1], [vector2], ...}
转化为一个二维图形,其中向量的索引为y,向量的索引为x

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

在没有任何数据的情况下,这是我能为您提供的最佳解决方案:

yourCell = {[0,0,0],[1,1,1],[2,2,2]}; % 1x3 cell
figure; 
plot(cell2mat(yourCell));
ylabel('Vector Values'); 
xlabel('Index of Vector');
它的情节是这样的:

希望这能有所帮助。

以下是我对您请求的解释。可能还有更优雅的解决方案

该代码生成一个点图,该点图将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

这里有一个简单的选项:

% 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
值上:

只要你的单元格数组只是一个向量列表,它就可以工作

编辑:对于不相等的向量

您必须使用带有
保持的for循环:

% 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


希望这能回答你的问题;)

你能给我们一些真实的数据让我们看看你在说什么吗?你的解释不是很清楚,所以每个y值都有一个x值的相关向量?这是怎么回事?为什么要交换
x
y
轴?他希望向量索引是一个
y
轴。@EBH我想我一定把这个问题和我刚才回答的另一个问题搞混了,哎呀。我改变了答案。对不起,我的向量大小不同,所以cell2mat(Celldata)不起作用