how to find the value of an index in a for loop
조회 수: 7 (최근 30일)
이전 댓글 표시
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?
댓글 수: 0
답변 (1개)
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
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 Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!