Error using sub2ind (line 43) Out of range subscript. How to solve this?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jordan Coombs
le 2 Déc 2020
Commenté : Jordan Coombs
le 2 Déc 2020
I have a code here that finds the data i need for specific cell values, for some reason it breaks when i get to the 27th iteration. Which to me doesn't make sense as everything should be within the desired range and the matrix dimensions agree, any help would be appreciated
PM = ('C:\Users\jorda\Desktop\Physics Project\PM Dust Not Removed\ACAG_PM25_V4GL03_199801_199812_0p05.nc');
x_val = ncread(PM,'LAT');
y_val = ncread(PM,'LON');
PM_val = ncread(PM,'PM25');
S = shaperead('C:\Users\jorda\Desktop\Physics Project\filt_country.shp');
[LAT,LON]=cdtgrid([0.05 0.05]);
strc1 = struct2cell(S);
strc2 = strc1(5,:)';
st = cell2mat(strc2);
i = 1;
while i <= 51
mat_zer=zeros(3600,7200);
isin1 = inpolygon(LON,LAT,S(i).X,S(i).Y);
mat_zer(isin1)=st(i);
[row1,col1] = find(mat_zer~=0);
mat_zer_pm = PM_val;
inds1 = sub2ind(size(mat_zer_pm),row1,col1);
new_mat1 = nan(size(mat_zer_pm));
new_mat1(inds1) = mat_zer_pm(inds1);
Country{i,2} = new_mat1;
i = i + 1;
end
0 commentaires
Réponse acceptée
Fangjun Jiang
le 2 Déc 2020
[row1,col1] is the index for mat_zer
in sub2ind(), it is using size(mat_zer_pm)
Do mat_zer_pm and mat_zer have the same size all the time?
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!