how to use conditional ezplot ?
2 views (last 30 days)
Show older comments
m=0;
nc=1.0;
na=2.0;
nb=1.0;
n=2;
lambda0=1.50e-6;
k0=2*pi/lambda0;
rc=5/k0;
a=1/k0; %0.211e-6;
b=1/k0; %0.305e-6;
%omega=rc core radius%
%W=beta/k;
%K=k/k0;
kc=@(K,W)k0*K*sqrt((nc)^2-(W)^2);
ka=@(K,W)k0*K*sqrt((na)^2-(W)^2);
kb=@(K,W)k0*K*sqrt((nb)^2-(W)^2);
t=@(K,W)(kc(K,W)*rc);
%For TE
xs=@(K,W)(cos(kb(K,W)*b)-(i/2)*((kb(K,W)/ka(K,W))+(ka(K,W)/kb(K,W)))*sin(kb(K,W)*b))*exp(-i*ka(K,W)*a);
ys=@(K,W)((i/2)*((kb(K,W)/ka(K,W))-(ka(K,W)/kb(K,W)))*sin(kb(K,W)*b))*exp(i*ka(K,W)*a);
xxs=@(K,W)real(xs(K,W));
xxxs=@(K,W)abs(xxs(K,W));
if xxxs<1;
Ritesh=@(K,W)(((-besselj(m+1,t(K,W))+(m/t(K,W))*besselj(m,t(K,W)))/besselj(m,t(K,W)))+((kc(K,W)*(((xxxxs(K,W))+sqrt((xxxxs(K,W))^2-1))^(n-1)-xs(K,W)-ys(K,W)))/(i*ka(K,W)*(((xxxxs(K,W))+sqrt((xxxxs(K,W))^2-1))^(n-1)-xs(K,W)+ys(K,W)))));
h1 = ezplot(Ritesh,[0.0*10^6/k0 31.4*10^6/k0 0 1]);
%h1 = ezplot(Ritesh,[0.0*10^6/k0 31.4*10^6/k0 0.008032 0.98394]);
set(h1,'Color','black','LineWidth',2);
else
end
0 Comments
Answers (1)
Walter Roberson
on 30 May 2016
Your xxxs is a function handle to a function that requires two arguments, but you are trying to use
if xxxs<1
which tests the function handle itself instead of applying the function handle to any arguments.
Are you trying to program it so that the formula in Ritesh applies in some parts of the ezplot but not in others? If so then what value should apply in the other parts? It is not possible to have ezplot apply only to some places -- but it is possible to create formula whose value is NaN in some places and meaningful values in others.
6 Comments
Walter Roberson
on 7 Jun 2016
It is not possible to do what you want to do.
surf() needs as input a 2D matrix of X values, a 2D matrix of Y values, and a 2D matrix of Z values. Every element of those must exist -- MATLAB does not permit "ragged" arrays or arrays with holes.
Your code inherently requires arrays with holes in it, because you refuse to define a value for the positions where xxxs(K,W) >= 1.
The code I built (and tested) for you defines some value for every grid position. It takes the short-cut of evaluating the main function at every location on the grid (not just where xxxs(K,W) < 1), but then taking care that every location where xxxs(K,W) < 1 is false gets given a value that is either -inf, +inf, or nan. surf() will silently not draw anything at positions where the Z is -inf, +inf, or nan (it is a design feature of surf, not a bug.)
If you want to get any further, you will need to adopt a similar strategy: for every K, W pair, you must have some output, even if the value is nan or inf. This does not inherently require that you compute at every location and then invalidate some of them (like I do), but if you choose to compute at only some locations then you need to assign the outputs of those locations into appropriate places in a larger grid to surf() after everything is complete. If you do want to compute at only some locations then you should read about logical indexing.
See Also
Categories
Find more on Particle & Nuclear Physics 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!