Why doesn't this code work ?

조회 수: 2 (최근 30일)
Add
Add 2016년 3월 31일
댓글: Walter Roberson 2016년 4월 6일
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
Walter Roberson
Walter Roberson 2016년 4월 6일

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Map Display에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by