线图:使用向量定义不同的线宽

line plot: Using a vector to define different lineWidths

我尝试创建一个线图,在一个变量中包含多条线 L。如果可以为每一行分配不同的线宽,那就太好了。以下引发错误消息:

lWidth = {1;2;3;4;5;1;2;3;4;5;1;2;3}; %% 13 Elements, as <data> is 13x4 matrix

L = line([data(:,1) data(:,2)]', [data(:,3) data(:,4)]', ...
    'LineWidth', lWidth(:), 'Color', 'red');

Error using line While setting the 'LineWidth' property of Line: Value not a numeric scalar

有没有办法使用向量中定义的线宽 lWidth

你不能使用 line 命令参数来做到这一点,但是 set 函数有一个特殊的语法来处理:

data = randn(13,4);
lWidth = {1,2,3,4,5,1,2,3,4,5,1,2,3}; %% 13 Elements, as data is 13x4 matrix

L = line([data(:,1) data(:,2)]', [data(:,3) data(:,4)]', 'Color', 'red');
set(L, {'LineWidth'}, lWidth(:));

请注意,属性 名称和 属性 值都必须是元胞数组,并且 属性 元胞数组的维度应与图形句柄数组的维度相同。