绘制单元格阵列 [英] Plotting a cell array
本文介绍了绘制单元格阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在Matlab中绘制具有以下格式的单元格数组:
I need to plot a cell array with the following format in Matlab:
{[vector1], [vector2], ...}
进入二维图,其中向量的索引为y,向量的索引为x
Into a 2D graph with the index of the vector as the y and the vector as the x
([vector1], 1), ([vector2], 2), ...
推荐答案
以下是一个简单的选择:
Here's a simple option:
% 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
值上:
so you plot each vector of x
on a separate y
value:
只要您的单元格数组只是矢量列表,它就可以工作.
It will work as long as your cell array is just a list of vectors.
适用于非相等向量
您必须在hold
中使用for循环:
You'll have to use a for loop with 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
希望这能回答您的问题;)
Hope this answers your question ;)
这篇关于绘制单元格阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文