How to colormap different functions with one gradient?

조회 수: 9 (최근 30일)
Niklas Kurz
Niklas Kurz 2021년 2월 1일
편집: Niklas Kurz 2021년 2월 2일
So carefully I prepared this piecewise function:
u = 0:0.01:2*pi;
v = 2*pi:0.01:4*pi;
w = 4*pi:0.01:6*pi;
f = 1+sin(3*u); %prepare image of first plot
c = -0.2;
a = exp(-(c*2*pi+2*pi));
g = a*exp(c*v+2*pi); %prepare image of second plot
A = a*exp(c*4*pi+2*pi);
h = A+A*sin(3*w); %prepare image of third plot
hold all
plot(u,f,'b-','LineWidth',2.5)
plot(v,g,'r-','LineWidth',2.5)
plot(w,h,'b-','LineWidth',2.5)
grid on
How do I add a total gradient? One plot I can handle but more are challenging me.
  댓글 수: 2
Jack Shannon
Jack Shannon 2021년 2월 2일
What do you mean by "total gradient"? Do you mean the gradient of each piece of your function?
Niklas Kurz
Niklas Kurz 2021년 2월 2일
편집: Niklas Kurz 2021년 2월 2일
Kinda: in general applying a total colormap over whole plot

댓글을 달려면 로그인하십시오.

답변 (1개)

Niklas Kurz
Niklas Kurz 2021년 2월 2일
편집: Niklas Kurz 2021년 2월 2일
So I found a sneaky workaround: just bring it in 3D and apply a simple command
[u,x] = meshgrid(0:0.01:2*pi);
ux = 1+sin(3.*x);
surf(u,x,ux)
hold on
[v,y] = meshgrid(2*pi:0.01:4*pi,0:0.01:2*pi);
vy = a*exp(c*v+2*pi);
surf(y,v,vy)
hold on
[w,z] = meshgrid(4*pi:0.01:6*pi,0:0.01:2*pi);
wz = A+A*sin(3*w);
surf(z,w,wz)
shading interp
colormap('jet')
From side this looks like a twodimensional plot. Wouldn't have to perform all these tricks IF MATLAB WOULD JUST BRING colormap command for 2D plots. I don't freaking understand why they don't.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by