필터 지우기
필터 지우기

how to find the value of an index in a for loop

조회 수: 3 (최근 30일)
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2023년 3월 6일
편집: Luca Ferro 2023년 3월 7일
lonP = 14.3;
latP = 40.4;
limlon=[min(longrd),max(longrd)];
limlat=[min(latgrd),max(latgrd)];
ic=0;
for i=1:length(longrd)
for j=1:length(latgrd)
ic=ic+1;
lonlatgrd(ic,1)=longrd(i);
lonlatgrd(ic,2)=latgrd(j);
end
end
grid_ang = calcola_ang_jacopo1(lonlatgrd,[lonP,latP]); %angles
for i2=1:length(grid_ang)
angsel=grid_ang(i2)*180/pi;
end
with this script and this function that I have attached, within this grid I have to try to identify the values of the i2 index in the different points of the grid. I have to try to understand how the values vary within the grid. Can anyone help me?

답변 (1개)

Luca Ferro
Luca Ferro 2023년 3월 6일
편집: Luca Ferro 2023년 3월 7일
if you just want to see how it varies numerically, print it:
for i2=1:length(grid_ang)
angsel=grid_ang(i2)*180/pi;
sprintf('%d ',i2) %EDIT: correcting a typo, see comments fro more
end
if you want to see how it varies graphically, plot it:
for i2=1:length(grid_ang)
angsel=grid_ang(i2)*180/pi;
id2_idx(i2)=i2; %store in in an array
end
plot(id2_idx,grid_ang) %plot it against the grid
  댓글 수: 2
ELISABETTA BILLOTTA
ELISABETTA BILLOTTA 2023년 3월 6일
it does not work.
in the first case it gives me the error "Unrecognized function or variable 'i_idx'."
and in the second case "Error using plot. Vectors must be the same length."
Luca Ferro
Luca Ferro 2023년 3월 7일
in the first one there is a typo, im sorry:
for i2=1:length(grid_ang)
angsel=grid_ang(i2)*180/pi;
sprintf('%d ',i2) %here is the typo, instead of i2_idx is just i2
end
The second one works on my machine, try to put a breakpoint on the plot line and check the dimensions of id2_idx and grid_ang and share them here

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by