Index exceeds the number of array elements.
4 views (last 30 days)
Show older comments
Hello,
I'm trying to create a topographic map, I keep getting a message in the comand window that says. Index exceeds the number of array elements. I needs some help making a topographic map for my class.
clf
disp('CTD_lat_lon.csv') % Display the file
table1 = readtable('CTD_lat_lon.csv') % creates a table from the data from the first OMG file
latitude = table2array(table1(:,2));
longitude = table2array(table1(:,3));
geoplot('latitude','longitude','-*')
geolimits([63.5 64],[-42 -40])
geobasemap topographic
4 Comments
the cyclist
on 18 Apr 2022
Edited: the cyclist
on 18 Apr 2022
@_ meant could you upload the file here, for us to use for debugging your code. You can use the paperclip icon in the INSERT section of the toolbar. Also, it would be helpful for you to report the complete error message, and what line of code causes it.
Answers (1)
the cyclist
on 18 Apr 2022
There are a couple issues with your code. First, MATLAB's algorithm to automatically detect the file delimiter seems to have gotten confused, so I set the explicitly. Also, the input file had some spurious whitespace characters that I got rid of.
More importantly, your enclosed the input arguments in quotes, which MATLAB just interprets as the string 'latitude' instead of the variable latitude. I fixed that up, too.
table1 = readtable('CTD_lat_lon.csv','delimiter',','); % creates a table from the data from the first OMG file
latitude = table2array(table1(:,2));
longitude = table2array(table1(:,3));
geoplot(latitude,longitude,'-*')
geolimits([63.5 64],[-42 -40])
geobasemap topographic
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!