How to use 2 variable in for loop?

2 visualizaciones (últimos 30 días)
U B
U B el 20 de Ag. de 2022
Comentada: Star Strider el 21 de Ag. de 2022
I want to use 2 variable in for loop. If we consider a circle then in polar coordinate I've already used r variable. Now I want to consider theta too. For eg.
i = 360;
for j =1:i
n = 1.5 ;
th(j) = j*pi/180 ;
X(j) = sin(th(j)) ;
end
figure(1)
plot(th*180/pi,X)
It give me a 1D line. Let us say for theta = 0. I want the whole range of theta from 0 to 360 to make it a 2D plot. How do I do that?
  1 comentario
U B
U B el 20 de Ag. de 2022
Movida: Star Strider el 20 de Ag. de 2022
I understood now, the question is not clear. The below image was in my mind when I asked the qiestion. Lets say for Theta= o line we have the set of value or sin function from the for loop. I wanted to expand the same value of sin(r) for theta 0 to 360 continousely. I'm showing only 4 theta position in the image. I'm aware its not going to be a simple code. I wanted have some input from others too.

Iniciar sesión para comentar.

Respuesta aceptada

U B
U B el 21 de Ag. de 2022
Found the solution.
rho = linspace(0,50,100); Nrho = length(rho); lambda = 50; k = 2*pi/lambda;
S00_1 = sin(k.*rho);
phi = 0:pi/30:2*pi; Nphi = length(phi);
[Rho,Phi] = meshgrid(rho,phi);
cPhi = cos(Phi); X = Rho.*cPhi;
sPhi = sin(Phi); Y = Rho.*sPhi;
S00 = zeros(Nphi,Nrho);
for i = 1:Nphi
S00(i,:) = S00_1;
end
figure, mesh(X,Y,S00);
  1 comentario
Star Strider
Star Strider el 21 de Ag. de 2022
That looks nothing like what you asked for in the earlier image!
If you want help on something in the future, ask the actual question you want an answer to.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by