how to find the value of an index in a for loop
7 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposte (1)
Luca Ferro
il 6 Mar 2023
Modificato: Luca Ferro
il 7 Mar 2023
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 Commenti
Luca Ferro
il 7 Mar 2023
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
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!