我想plot3隨著陣列索引的進展使用不同的顏色。
我有 3 個變數:x, y, z. 所有這些變數都包含時間線進度中的值。
例如:
x = [1, 2, 3, 4, 5];
y = [1, 2, 3, 4, 5];
z = [1, 2, 3, 4, 5];
plot3(x, y, z, 'o')
我希望看到從 ( x(1), y(1), z(1)) 到繪圖中的最后一個值( )的顏色變化x(5), y(5), z(5)。如何動態更改此顏色?
uj5u.com熱心網友回復:
在我看來,這里的方法是使用
使用plot3你可以做同樣的事情,但它需要一個回圈:
cMap = jet(numel(x)); % Generates colours on the desired map
figure
hold on % Force figure to stay open, rather than overwriting
for ii = 1:numel(x)
% Plot each point separately
plot3(x(ii), y(ii), z(ii), 'o', 'color',cMap(ii,:))
end

plot3如果您想在元素之間連續使用彩色線條,我只會使用該選項,而這scatter3無法做到:
cMap = jet(numel(x)); % Generates colours on the desired map
figure
hold on % Force figure to stay open, rather than overwriting
for ii = 1:numel(x)-1
% Plot each line element separately
plot3(x(ii:ii 1), y(ii:ii 1), z(ii:ii 1), 'o-', 'color',cMap(ii,:))
end
% Redraw the last point to give it a separate colour as well
plot3(x(ii 1), y(ii 1), z(ii 1), 'o', 'color',cMap(ii 1,:))

注意:在 R2007b 上測驗和匯出影像,使用 R2021b 檔案交叉檢查語法
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/354187.html
上一篇:列的排序行的Matlab等效項
