Why doesn't this code work ?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
2016년 3월 31일
"Without the map code" - which is the "map code"? Please format your code peroperly using the "{} Code" button.
답변 (2개)
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()
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]).
참고 항목
카테고리
Help Center 및 File Exchange에서 Map Display에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!