How to run a for loop when variables are different lengths?
이전 댓글 표시
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;
채택된 답변
추가 답변 (2개)
Image Analyst
2020년 9월 7일
편집: Image Analyst
2020년 9월 7일
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
2020년 9월 7일
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
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!