How to run a for loop when variables are different lengths?
Mostrar comentarios más antiguos
Here I have outlined two variables, delta and phi. I want to calculate beta for every possible combination of phi and delta but am not sure how since they are different lengths.
delta = -23.28:0.01:23.28;
phi = -90:1:90;
beta = phi - delta;
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 7 de Sept. de 2020
Editada: Image Analyst
el 7 de Sept. de 2020
You can do it vectorized using meshgrid(). Try this:
delta = -23.28:0.01:23.28;
phi = -90:1:90;
[deltaAll, phiAll] = meshgrid(delta, phi);
beta = phiAll - deltaAll;
imshow(beta, [], 'XData', delta, 'YData', phi);
colormap(jet(256));
colorbar;
axis('on', 'image');
xlabel('delta', 'FontSize', 24);
ylabel('phi', 'FontSize', 24);

Sulaymon Eshkabilov
el 7 de Sept. de 2020
Hi,
Here is the solution to your exercise:
delta = -23.28:0.01:23.28;
phi = -90:1:90;
for ii = 1:numel(delta)
for jj=1:numel(phi)
beta(ii,jj) = phi(jj) - delta(ii);
end
end
Categorías
Más información sobre Loops and Conditional Statements 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!