Check every element of an array with if statement

25 vues (au cours des 30 derniers jours)
david Price
david Price le 13 Juil 2021
Commenté : david Price le 13 Juil 2021
I'm writing a code that ends up giving me an array of numbers liksuch as this:
function R = RMapA()
z = [0.2+(-500:.05:500)*1i];% 0.5+(-500:.05:500)*1i 1+(-500:.05:500)*1i 2+(-500:.05:500)*1i 4+(-500:.05:500)*1i 10+(-500:.05:500)*1i (-500:.05:500)-10i (-500:.05:500)-4i (-500:.05:500)-2i (-500:.05:500)-1i (-500:.05:500)-0.5i (-500:.05:500)-0.2i (-500:.05:500)+0.2i (-500:.05:500)+0.5i (-500:.05:500)+1i (-500:.05:500)+2i (-500:.05:500)+4i (-500:.05:500)+10i 0+(-500:.05:500)*1i ];
R = (z-1)./(z+1);
x = abs(R)
%if any( x <= 1)
plot(real(R),imag(R),'b');
title('R Plane Chart');
%end
end
I'd like to add a correct 'if statement' that will check every element of x, and for any one that is <= 1 , it will plot the R.
is this possible and if so, how?
if you have any more questions i'll asnwer the best i can. I'm extremely new to this.
thank you.

Réponse acceptée

David Hill
David Hill le 13 Juil 2021
z = [0.2+(-500:.05:500)*1i];
R = (z-1)./(z+1);
x = abs(R);
idx=x<=1;
plot(real(R(idx)),imag(R(idx)),'b');
title('R Plane Chart');
  2 commentaires
Cris LaPierre
Cris LaPierre le 13 Juil 2021
You can learn about logical arrays in Ch12 of MATLAB Onramp.
david Price
david Price le 13 Juil 2021
thanks!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Visual Exploration dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by