How to color system of PDEs with two population
Show older comments
Dear Matlab Team,
I have a system of PDEs with two equations (two population, V, W) written in polar coordinate. My diffusion is nonhomogeneous and I get the centripetal pattern from each population. For example from 0 degree to 30 degree is V and from 30 to 60 is W and this process repeates. Now, I need to color V as a red and W as a blue in a circle and I use this code, but since the green channel is zero, it is black between grid points.
Could you help me how to finx this to have a smoth diffusion with no black distance?
[Theta, R] = meshgrid(theta, r); % [51, 60]
[X, Y] = pol2cart(Theta, R); % [51, 60]
Vnorm = V / (max(V(:)) + 1e-8);
Wnorm = W / (max(W(:)) + 1e-8);
RGB = zeros(Nr+1, Ntheta, 3); % [r, theta, color channel]
RGB(:,:,1) = Wnorm; %
RGB(:,:,2) = 0; %
RGB(:,:,3) = Vnorm; %
clf;
surf(X, Y, zeros(size(X)), RGB, 'EdgeColor', 'none');
view(2);
axis equal off;
title(['V (Blue) , W (Red), t = ', num2str(t*dt)]);
colorbar;
drawnow;
Thank you !!
2 Comments
William Rose
on 10 Jul 2025
It would help to have runnable code, so we can actually see the problem. Your posted code is un-runnable since various scalars, vectors, and arrays are not provided. Please provide the simplest possible runnable code and run it in the Matlab Answers window. For example, you could save the necessary variables in a .mat file, attach it, then load it at the start of the script posted on Matlab Answers.
You said "For example from 0 degree to 30 degree is V and from 30 to 60 is W and this process repeates." I'm not sure I understand what you mean. Here is an example of V and W, where V is zero from 30 to 60 deg, 90 to 120, etc.; and W is zero from 0 to 30, 60 to 90, etc. Is that what you meant?
r=(0:0.2:10)'; Nr=length(r);
theta=0:pi/36:2*pi; Nt=length(theta);
Vr=tukeywin(Nr); Vt=max(sin(6*theta),0);
Wr=tukeywin(Nr); Wt=max(-sin(6*theta),0);
V=Vr*Vt;
W=Wr*Wt;
% Plot Vr, Wr, Vt, Wt
figure
subplot(211), plot(r,Vr,'-rx',r,Wr,'-bo')
xlabel('Radius'); legend('V(r)','W(r)')
subplot(212), plot(theta,Vt,'-rx',theta,Wt,'-bo')
xlabel('Theta'); legend('V(theta)','W(theta)')
By the way, it looks like your posted code assigns V to blue and W to red, which is the opposite of what you said you wanted. No big deal.
Accepted Answer
More Answers (0)
Categories
Find more on Color and Styling in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


