Pass plot parameters as a vector

2 vues (au cours des 30 derniers jours)
Jason Butler
Jason Butler le 12 Mar 2023
Modifié(e) : Voss le 12 Mar 2023
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

Réponses (1)

Voss
Voss le 12 Mar 2023
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.'))

Catégories

En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange

Tags

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by