Why doesn't this code work ?

1 次查看(过去 30 天)
Add
Add 2016-3-31
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 个评论
Jan
Jan 2016-3-31
"Without the map code" - which is the "map code"? Please format your code peroperly using the "{} Code" button.
Add
Add 2016-4-5
% 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

请先登录,再进行评论。

回答(2 个)

Walter Roberson
Walter Roberson 2016-4-5
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 个评论
Add
Add 2016-4-5
编辑:Add 2016-4-5
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.

请先登录,再进行评论。


Chad Greene
Chad Greene 2016-4-5
编辑:Chad Greene 2016-4-5
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 个评论
Add
Add 2016-4-6
I am not using your circles function. The problem is with the map boundary, it calls its axis and other axes are suppressed.
Thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Geographic Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by