Pass plot parameters as a vector

8 次查看(过去 30 天)
Jason Butler
Jason Butler 2023-3-12
编辑: Voss 2023-3-12
I can pass multiple vectors in a single call to plot
x = linespace(0,1000,10)
y(1,:)= exp(x);
y(2,:) = log(x);
y(3,:) = x.^2;
plot(x',y');
and this works. How can I also pass in properties for each plot in a single call? I've tried numerous variations of
colors = ['b','g','r'];
plot(x',y', colors');
but I always get errors

回答(1 个)

Voss
Voss 2023-3-12
x = linspace(0,1,10); % I changed the domain so you can see the lines
y(1,:)= exp(x);
y(2,:) = log(x);
y(3,:) = x.^2;
colors = 'bgr';
Option 1: plot(x1,y1,linespec1,x2,y2,linespec2,...)
figure
plot(x,y(1,:),colors(1),x,y(2,:),colors(2),x,y(3,:),colors(3));
Option 2: plot(x,y,linespec) in a loop
figure
hold on
for ii = 1:size(y,1)
plot(x,y(ii,:),colors(ii));
end
Option 3: h = plot(x,y); then set colors
figure
h = plot(x,y.');
set(h,{'Color'},num2cell(colors.'))

类别

Help CenterFile Exchange 中查找有关 Creating, Deleting, and Querying Graphics Objects 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by