Pass plot parameters as a vector

4 views (last 30 days)
Jason Butler
Jason Butler on 12 Mar 2023
Edited: Voss on 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

Answers (1)

Voss
Voss on 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.'))

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!