Pass plot parameters as a vector
조회 수: 8 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
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.'))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating, Deleting, and Querying Graphics Objects에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


