Using For Loop to get different outcomes

1 visualizzazione (ultimi 30 giorni)
Melissa Hopkins
Melissa Hopkins il 3 Ott 2019
Hi all!
I'm trying to write a code where I can give two different properties in the graph given the value of psi.
For example, I have a function where I specify psi_value:
isosurface_STO_orbital(atom_pos,STO_parameters,coeff,psi_value)
I would like for it to do something like this:
for psi_value= .05 or .15 or .25 or .35;
s_plot= .8;
for psi_value_j=.1 or 2 or .3 or .4
s_plot=.2;
What would be a good way to get this outcome?
Thanks!
  1 Commento
Melissa Hopkins
Melissa Hopkins il 3 Ott 2019
psi_value_j was meant to be just psi_value, sorry for the confusion

Accedi per commentare.

Risposte (1)

Guillaume
Guillaume il 3 Ott 2019
if ismember(psi_value, [0.05, 0.15, 0.25, 0.35]) %maybe use ismembertol
s_plot = 0.8;
else
s_plot = 0.2;
end
Note that your if your psi_value is the result of a calculation it may never be exactly equal to 0.05 (or 0.15, or...) in which case use ismembertol instead of ismember.
  1 Commento
Melissa Hopkins
Melissa Hopkins il 3 Ott 2019
Awesome, thank you! Now that I have that fixed, I'm running into another issue if anyone sees the problem. I get an error code that face_alpha is undefined in the patch. Maybe I was going about this the wrong way with the loop? I'm having a hard time understanding
if ismember(psi_value,[.05 .15 .25 .35])
face_value=.8;
else
face_value=.2;
end
end
% draw positive isosurface
psi_surface=isosurface(X_grid,Y_grid,Z_grid,psi_grid,psi_value);
patch(psi_surface,'FaceColor',[0 90 255]/255,'FaceAlpha',face_value,'EdgeColor','none');

Accedi per commentare.

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by