加快样条曲线的着色段?

Sib*_*ing 5 matlab plot colors matlab-figure

我试图用不同的RGB值对样条曲线的片段进行着色.非常感谢@Suever,我有一个工作版本:

x = [0.16;0.15;0.25;0.48;0.67];
y = [0.77;0.55;0.39;0.22;0.21];
spcv = cscvn([x, y].'); % spline curve
N = size(x, 1);
figure;
hold on;
for idx = 1:N-2
    before = get(gca, 'children'); % before plotting this segment
    fnplt(spcv, spcv.breaks([idx, idx+1]), 2);
    after = get(gca, 'children'); % after plotting this segment
    new = setdiff(after, before);
    set(new, 'Color', [idx/N, 1-idx/N, 0, idx/N]); % set new segment to a specific RGBA color
end
hold off;
Run Code Online (Sandbox Code Playgroud)

现在我希望加快速度.可能吗?

Tas*_*nou 4

本身没有明确的基准,但您可以通过
a 轻松对其进行矢量化。收集绘制的点并将它们分成“段”(例如使用该buffer函数)
b.设置'color'Children 的属性(感谢 @Suever 指出这可以直接在对象句柄数组上完成

%% Get spline curve
x = [0.16; 0.15; 0.25; 0.48; 0.67];
y = [0.77; 0.55; 0.39; 0.22; 0.21];
spcv = cscvn ([x, y].');

%% Split into segments
pts = fnplt (spcv);   xpts = pts(1,:).';   ypts = pts(2,:).';
idx = buffer ([1 : length(xpts)]', 10, 1, 'nodelay'); % 10pt segments
lastidx=idx(:,end); lastidx(lastidx==0)=[]; idx(:,end)=[]; % correct last segment

% Plot segments
plot (xpts(idx), ypts(idx), xpts(lastidx), ypts(lastidx), 'linewidth', 10);

% Adjust colour and transparency
Children = flipud (get (gca, 'children'));
Colours  = hsv (size (Children, 1)); % generate from colourmap
Alphas   = linspace (0, 1, length (Children)).'; % for example
set (Children, {'color'}, num2cell([Colours, Alphas],2));
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

注意:正如评论部分中所指出的(感谢@Dev-iL),按照您要求的方式将颜色设置为 RGBA 四元组(即与简单的 RGB 三元组相反)是较新的(目前也未记录) Matlab 功能。例如,此代码在 2013b 中不起作用。