【发布时间】:2018-09-19 10:47:22
【问题描述】:
我在 MATLAB 中通过gscatter 绘制。速度与年份的关系图。现在在我的情况下还有另一个列向量或表,其中包含相应的绘图点字符串。该表是int 变量。
我想显示图表上绘制点的 int 变量的相应文本。谁能帮帮我?
这是我数据的link。
这是我的代码:
T = readtable('Data_Serial.xlsx');
int = T.Int;
BW = T.Band;
type = T.Type;
year = T.Year;
g = {type};
labels = cellstr(int);
% Plot Data
f = figure;
box on;
gscatter(year,BW,g,'rkgb','o*',8,'on','Year','Speed')
hold on;
text(year(:,1), BW(:,2), labels, 'VerticalAlignment','bottom', ...
'HorizontalAlignment','right')
显示如下错误:
>> Data_Serial
Index exceeds matrix dimensions.
Error in Data_Serial (line 16)
text(year(:,1), BW(:,2), labels, 'VerticalAlignment','bottom', ...
【问题讨论】:
-
@gehbiszumeis 感谢您的回答。我看到的那个例子。在该示例中,他们使用
labels = cellstr( num2str([1:10]') );将行号转换为字符串。就我而言,我将字符串表存储在int中。所以我把labels = cellstr(int);设置为我正在使用scatter函数,它使我能够根据另一个变量进行绘图。但是那个标签仍然不起作用。我已经更新了我的问题中的代码。
标签: matlab plot text scatter-plot