在 matlab 中绘制向量

发布于 2024-10-19 09:53:14 字数 579 浏览 0 评论 0原文

我遇到这种情况,无法以正确的方式解决。问题是这样的: 我有3个向量:

  • Vector1 = [name1 name2 name3 name4 ... nameN] (字符串名称)
  • Vector2 = [time1 time2 time3 time4] (Double)
  • Vector3 = [time1:name4 time2:name1 time3:name1 time4:name1] (double :String)

我想在matlab中执行以下操作:

1-将向量1放入Y轴并带有名称 - 我可以用这段代码来做到这一点:

   set(gca, 'YTick',1:N, 'YTickLabel',Names(:,1))

2- 将向量 2 放在 X 轴上,以模拟时间线

3- 一旦我们有了 X 轴和 Y 轴,我想使用 3 个向量在图中绘制点

例如, 3 个向量包含连续的时间戳,并且在每个时间戳中执行 nameN,所以我想使用 3 个向量作为输入在图中绘制一个点。

有什么建议吗?提前致谢

I have this situation and I can't solve it in the proper way. The problem is this:
I have 3 vectors:

  • Vector1 = [name1 name2 name3 name4 ... nameN] (string names)
  • Vector2 = [time1 time2 time3 time4] (Double)
  • Vector3 = [time1:name4 time2:name1 time3:name1 time4:name1] (double:String)

I want to do the following in matlab:

1- Put Vector 1 in Y axis with names
- I could do it with this code:

   set(gca, 'YTick',1:N, 'YTickLabel',Names(:,1))

2- put Vector 2 in X axis with, to simulate time line

3- Once we have both axis X&Y I'd like to use the 3 Vector to plot point in the graph

For example, 3 Vector contains secuentially timestamps and in each timestamp is executed the nameN, so I'd like to plot a dot in the graph using 3 vector as input.

Any suggestion?Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

幼儿园老大 2024-10-26 09:53:14

您需要将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])

You need to convert the names in vector3 to numbers, then you can call the plot command.

For example

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])
恍梦境° 2024-10-26 09:53:14

一种方法是,

  1. 仅将值放入 Vector3 中
  2. ,然后使用绘图(向量2,向量3)

另外,我建议将向量1重命名为“比例”,将向量2重命名为“时间”,将向量3重命名为“值”。这应该有助于你清楚地了解你正在使用什么等等。希望这会有所帮助。

One way to do it is,

  1. put only the values in Vector3
  2. then use plot(vector2, vector3)

Also I suggest to rename vector1 to "scale", vector2 to "time", and vector3 to "values". That should help to get your mind clear about what you are using with what etc. Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文