MATLAB Answers

Can I pcolor base on wavelength, any colormap can do so?

21 views (last 30 days)
chia ching lin
chia ching lin on 2 Dec 2020
Answered: Walter Roberson on 2 Dec 2020
I'm tryimg to simulate diffraction pattern base on different wavelength. I can only find color map base on intensity. Is there any function or toolbox that I can change the color base on wavelength?
lambda=650e-9; % wavelength
a=10e-6; % obstruct disc radius
x=linspace(-0.2,0.2,1000);
y=x;
[X,Y]=meshgrid(x,y);
r=sqrt(X.^2+Y.^2);
% diffraction pattern
u=2.*pi.*a./lambda;
J=besselj(1,u.*sin(r));
I=(u.*((1+cos(r))./2).*(J./sin(r))).^2;
figure(1)
L=lambda.*1e9;
pcolor(X,Y,I); shading flat; axis image;
title([num2str(L)]);

  0 Comments

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 2 Dec 2020
When you pcolor(X,Y,I) then the I data will be used to decide which color information is used. By default, the numerically lowest value in I will be mapped to the first color in the color table, and the numerically largest value in I will be mapped to the last color in the color table, and all other values will be mapped according to the (value minus lowest) relative to (highest minus lowest) .
If you want the color to be based on some other information, then you should pass that other information instead of I
You currently have two independent variables (X, Y) and one dependent variable I . It looks like you intend to extend that to additional wavelengths, in which case you would have three independent variables (X, Y, wavelength) and one dependent variable. That requires a 4D plot, which are difficult to do. You could use volumeViewer with transparency to try to convey the information, but that probably will not work well. So you should consider either using slice() or using isosurface()

  0 Comments

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by