我有这种情况,我无法以正确的方式解决。问题是这样的:我有3个向量:
- Vector1 = [名称1名称2名称3名称4 ...名称N](字符串名称)
- Vector2 = [time1 time2 time3 time4](双精度)
- Vector3 = [time1:name4 time2:name1 time3:name1 time4:name1](双精度:字符串)
我想在matlab中执行以下操作:
1-将向量1放在名称为Y的轴上-我可以使用以下代码进行操作:
set(gca, 'YTick',1:N, 'YTickLabel',Names(:,1)) 2-将向量2放在X轴上,以模拟时间线
3-一旦我们有了X和Y轴,我想使用3 Vector在图中绘制点
例如,3 Vector包含安全时间戳,在每个时间戳中执行nameN,因此我想使用3 vector作为输入在图中绘制一个点。
有什么建议吗?谢谢
回答:
您需要将vector3的名称转换为数字,然后才能调用plot命令。
例如
names = {'a','b','c','d'}; %# use a cell array (curly brackets) for strings time = [10 20 30 40 50]; data = {10,'d';20,'b';40,'c'} %# convert data to numeric xData, yData xData = cell2mat(data(:,1)); [dummy,yData] = ismember(data(:,2),names); %# plot plot(xData,yData,'.') %# plot dots set(gca,'YTick',1:length(names),'YTickLabel',names,'XTick',time) %# make sure the axes limits aren't too tight xlim([0,60]),ylim([0,5])
更多&回答...