Problem using shapefile in matlab

7 visualizaciones (últimos 30 días)
Jose Luis
Jose Luis el 12 de Jun. de 2014
Comentada: Kelly Kearney el 12 de Jun. de 2014
I'm working with the free m_map toolbox for the first time. I would like to overlay an image with a vector (shape file) "clip" by doing this:
M=m_shaperead('clip');
clf;
for k=1:length(M.ncst),
line((M.ncst{k}(:,1)),M.ncst{k}(:,2));
end;
I got the following message:
Subscript indices must either be real positive integers or logicals.
Error in carta4 (line 5)
line((M.ncst{k}(:,1)),M.ncst{k}(:,2));
these are simple positive lat/lon values, for example: 13.2130 17.2304, even when transforming these values to integer ( 13210 17230) the error persists, could someone explain me which is the easiest way of reading shapefiles with the m_map toolbox?
Thank you very much

Respuestas (2)

Kelly Kearney
Kelly Kearney el 12 de Jun. de 2014
I don't see anything wrong with that code, and substituting another shapefile works fine. Can you show us the details of M?
Are you sure you copied your code correctly? The error isn't in the shapefile read, but rather in the plotting line. It seems to indicate that k isn't an integer, but I'm not sure how that could occur.
On a side note, you seem to have an extra set of parentheses in there (around M.ncst{k}(:,1)), but again I don't think that would cause any issues.

Jose Luis
Jose Luis el 12 de Jun. de 2014
Thank you for your answer,I don't have any idea why this happens, an example of the data:
M =
version: 1000
shape_type: 5
MBRx: [2x1 double]
MBRy: [2x1 double]
MBRz: [2x1 double]
MBRm: [2x1 double]
filelength16: 98
type: 5
ctype: 'polygon'
ncst: {12x1 cell}
mbr: [12x4 double]
dbfversion: 3
dfbdate: [2014 6 10]
fieldnames: {'REC_NUM' 'DATA_VALUE'}
dbfdata: {12x2 cell}
REC_NUM: {12x1 cell}
DATA_VALUE: {12x1 cell}
M.ncst
ans =
[ 98x2 double]
[151x2 double]
[222x2 double]
[ 69x2 double]
[426x2 double]
[843x2 double]
[373x2 double]
[554x2 double]
[406x2 double]
[111x2 double]
[551x2 double]
[372x2 double]
M.ncst{1}
ans =
3.6050 11.6969
3.5916 11.6746
3.5612 11.6016
3.5397 11.5000
2.0901 11.5000
2.1854 11.5972
2.2062 11.6009
2.2574 11.6479
2.3057 11.6744
2.3097 11.6797
2.3038 11.6858
2.3066 11.6968
2.2992 11.7208
2.3036 11.7352
2.3191 11.7562
2.3382 11.7702
2.3403 11.7853
2.3709 11.7928
2.3677 11.8133
2.3831 11.8276
2.3754 11.8333
2.3754 11.8444
2.3792 11.8540
2.4026 11.8705
2.3944 11.8892
2.4054 11.9016
2.4047 11.9096
2.3901 11.9308
2.4015 11.9529
2.4125 11.9494
2.4200 11.9551
2.4312 11.9553
2.4326 11.9751
2.4427 11.9822
2.4588 11.9762
2.4684 11.9946
2.4600 12.0321
2.4227 12.0895
2.3998 12.1426
2.3873 12.2422
2.4037 12.2493
2.4254 12.2514
2.4345 12.2632
2.4560 12.2545
2.4645 12.2722
2.4944 12.2686
2.5056 12.2774
2.5080 12.2886
2.5143 12.2944
2.5360 12.2745
2.5735 12.2820
2.5878 12.2997
2.5960 12.2972
2.6086 12.3008
2.6250 12.2948
2.6631 12.3041
2.6759 12.2965
2.6820 12.2795
2.6862 12.2806
2.7158 12.3493
2.7288 12.3626
2.7329 12.3621
2.7751 12.4110
2.7946 12.4183
2.8058 12.4174
2.8666 12.3897
2.9585 12.2944
2.9814 12.2859
3.0015 12.2723
3.0198 12.2368
3.0489 12.2107
3.0568 12.1906
3.1212 12.1534
3.1209 12.1405
3.1248 12.1363
3.1524 12.1215
3.1898 12.0797
3.2617 12.0161
3.2485 11.9941
3.2688 11.9729
3.2756 11.9407
3.2910 11.9314
3.3020 11.8941
3.3076 11.8876
3.3394 11.8852
3.3709 11.8910
3.3840 11.8845
3.4120 11.8807
3.4400 11.8604
3.4685 11.8629
3.4850 11.8543
3.5143 11.8246
3.5263 11.7834
3.5585 11.7766
3.5594 11.7651
3.5484 11.7437
3.5551 11.7304
3.6050 11.6969
  1 comentario
Kelly Kearney
Kelly Kearney el 12 de Jun. de 2014
Okay, that all looks fine. What is the value of k when the code throws the error?

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by