Why doesn't this code work ?

2 views (last 30 days)
Add
Add on 31 Mar 2016
Commented: Walter Roberson on 6 Apr 2016
I have this code for plotting circles around GPS stations, it works fine, but when I plot the map and try to plot those stations on the map, it doesn't work. I don't understand why.
clc
clear all; close all;
scriptPath = 'D:\Data\Matlab_scripts\';
GPS_LOC_dir = 'D:\Data\GPS_stations\';
% % This part read the GPS stations information
GPS_station_file =[GPS_LOC_dir 'GPS_Stations.txt'];
delimiter ={'\t',' '};
startRow = 2;
formatSpec = '%s%f%f%[^\n\r]';
fileID = fopen(GPS_station_file,'r');
dataArray2 = textscan(fileID, formatSpec, 'Delimiter', delimiter,'HeaderLines' ,startRow-1, 'MultipleDelimsAsOne', true, 'EmptyValue' ,NaN, 'ReturnOnError', false);
fclose(fileID);
CODE2 = dataArray2{:, 1};
LAT2 = dataArray2{:, 3};
LON2 = dataArray2{:, 2};
% This is the part that draws the Indian map.
whitebg('w');
load coast
m_proj('mercator','long',[68 98],'lat',[0 30]);
axesm('MapProjection','mercator','MapLatLimit',[0 30],'MapLonLimit',[68 98]);
framem
m_coast('patch',[0.7 0.7 0.6]);
m_grid('xtick',12,'ytick',8);
xlabel('Longitude (deg)');
ylabel('Latitude (deg)');
% End of map plot
rad = km2deg(100,'earth');
n = length(LAT2);
r = ones(n,1)*rad;
c = [LON2,LAT2];
plot(LON2,LAT2,'r*');
text(LON2,LAT2, CODE2 ,'fontsize',10,'fontname','times','fontweight','bold');%
hold on
[h,xs,ys] = circles(r,c,'color','g','lineWidth',2);
hold off
it shows only the map, the circles and the stations vanishes.
Without the map codes, I get everything right. But introducing the map, I get only the map.
Can anyone help ? Thanks, Add.
  2 Comments
Jan
Jan on 31 Mar 2016
"Without the map code" - which is the "map code"? Please format your code peroperly using the "{} Code" button.
Add
Add on 5 Apr 2016
% This is the part that draws the Indian map.
whitebg('w');
load coast
m_proj('mercator','long',[68 98],'lat',[0 30]); axesm('MapProjection','mercator','MapLatLimit',[0 30],'MapLonLimit',[68 98]);
framem
m_coast('patch',[0.7 0.7 0.6]);
m_grid('xtick',12,'ytick',8);
xlabel('Longitude (deg)'); ylabel('Latitude (deg)'); % End of map plot

Sign in to comment.

Answers (2)

Walter Roberson
Walter Roberson on 5 Apr 2016
You should not try to combine plot() and the mapping toolbox on the same axes. The mapping toolbox set up unusual axes properties that plot() does not know about. Instead of plot() you should use plotm()
  1 Comment
Add
Add on 5 Apr 2016
Edited: Add on 5 Apr 2016
Thanks Roberson. But using plot(m) is not helping. In other cases, using mapping toolbox it works, but I want a solution such that I would be able to plot this without the mapping toolbox.

Sign in to comment.


Chad Greene
Chad Greene on 5 Apr 2016
Edited: Chad Greene on 5 Apr 2016
I suspect you should not call axesm or framem if you're also using m_map functions.
Where'd you get the circles function? If it's mine, check the inputs. My circles function takes inputs in the form circles(x,y,r), but it looks like you're entering circles(r,[x y]).
  2 Comments
Add
Add on 6 Apr 2016
I am not using your circles function. The problem is with the map boundary, it calls its axis and other axes are suppressed.
Thanks

Sign in to comment.

Categories

Find more on Geographic Plots 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!