Creating a loop within a loop
Mostrar comentarios más antiguos
[EDIT: 20111027 17:42 CDT - merge another revised question - WDR]
[EDIT: 20111027 17:10 CDT - merge revised question - WDR]
Hello everyone,
I'm presently trying to construct a loop within a loop that based on changing date (1:365) and changing latitude (0:90), and the subsequent effects on the below equation:
x=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*((t+1)+43200));
I've tried this:
for t=1:365
x(t+1)=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*((t+1)+43200));
for lat=0:90
x(lat+1)=sin(lat+1).*sin(Dec)+cos(lat+1).*cos(Dec).*cos(wd.*(t+43200));
end
end
x
and this:
for t=365;
lat=1;
x=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200));
while length(lat)==90;
lat=lat+1;
while length(t)==365;
t=t+1;
end
end
end
x;
Anyone have any ideas?
[Revised Question]
Hello everyone,
I'm presently trying to construct a loop with two variables, changing date (1:365) and changing latitude (0:90), with the aim of the loop to calculate all the possible outputs of the below equation:
x=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200));
So far i've tried this but it doesn't work:
lat=1;
t=1;
x=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200));
while length(lat)==90;
lat=lat+1;
x=[x,sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200))];
while length(t)==365;
t=t+1;
x=[x,sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200))];
end
end
x
[Revision #2]
I'm just trying to construct a loop that calculates all the possible outputs based on two variables (lat=0:90, t=1:365), with the equation:
x=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200));
So far, my latest attempt is:
for lat=0:90;
for t=1:365;
x(lat,t)=sin(lat).*sin(Dec)+cos(lat).*cos(Dec).*cos(wd.*(t+43200));
end
end
x
Can anyone recommend a workable method?
1 comentario
the cyclist
el 27 de Oct. de 2011
Please make your code more readable by using the "Code" markup button.
Respuesta aceptada
Más respuestas (1)
Walter Roberson
el 27 de Oct. de 2011
[T,LAT] = ndgrid(1:365,0:90);
x=sin(LAT).*sin(Dec)+cos(LAT).*cos(Dec).*cos(wd.*((T+1)+43200));
1 comentario
Josh
el 27 de Oct. de 2011
Categorías
Más información sobre Functions en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!