Info

This question is closed. Reopen it to edit or answer.

Out of range subscript

2 views (last 30 days)
Lionel Dété
Lionel Dété on 3 May 2017
Closed: Lionel Dété on 4 May 2017
Hello, I got the famous "Out of range subscript" problem :
Error using sub2ind (line 43)
Out of range subscript.
Currently, I'm trying to use vector instead of loop in my program. Here is some code :
% Sorry I'm french, so comment are also in french.
vlat=vlat';
for i=2:length(vlong) % fl_getbathy utilise des matrices de taille identique pour fonctionner
i
vlat(:,i)=vlat(:,i-1); % Il faut donc copier (en colonne) la latitude autant de fois qu'il y a de longitude (dans une ligne)
end
[m,n]=size(vlat); % on récupère la taille de la matrice m*n (m : colonne, n : longueur)
vlong=vlong'
for i=2:m % On fait de même avec la longitude
i
vlong(:,i)=vlong(:,i-1); % On copie autant de fois (en ligne) la longitude qu'il de latitude (dans une colonne)
end
vlong=vlong';
topo1=fl_getBathy(vlong,vlat,lat1,long1,Bath1) % <== The problem happen here
I tryied to fix it with some tips that I saw on the site but nothing worked well.
Anyone have an idea ?
Is it possible that the function fl_getBathy can't handle vector for "vlong" "vlat" ? I mean if the function counldn't handle it which error should occur ?
P.S : Sorry if my English is not that good, trying my best to be clear.
  6 Comments
Stephen23
Stephen23 on 4 May 2017
Lionel Dété's "Answer" moved here:
Sorry... It seems like I miss lot of things here. I will try to answer to all of the comment :
So, First, here is the code use for fl_getBathy :
function bathy=getBathy(la,lo,vlat,vlon,imada)
bathy = NaN;
l_buffer = abs(vlat-la);
l_indicesLat = find(l_buffer == min(l_buffer));
l_buffer = abs(vlon - lo);
l_indicesLon = find(l_buffer == min(l_buffer));
bathy = imada(l_indicesLat(1),l_indicesLon(1));
For my input : vlong, vlat are matrix 10980*10980 lat1, long1 and Bath1 are matrix 62*97
I didn't even show to the function itself before (just found it..)
If I understand well, vlat and la have to be the same size right (like vlon and lo) ?
Thank you for the help, and thank you for the advice in the program improvement
Lionel Dété
Lionel Dété on 4 May 2017
Ok, I just find a way to avort the problem. I resize the matrix i get before to create my mask. Thank you all for helping !

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!