Plotting multiple trajectories on map

12 次查看(过去 30 天)
I have a rather strange one.
I need to plot multiple trajectories on a map. Right now, I am manually adding each latitude and longitude to the script and plotting away. This is easy enough for a few lines, but not in the long run.
The variables tdump* are specific to a trajectory and are from individually named text files. So... these change depending on the text file. What I have been doing is importing the information I need from each text file and assigning it a numeric variable with the same name.
%Import data from file. Get rid of ugly header.
filename = 'tdump85072712.txt';
delimiterIn = ' ';
headerlinesIn = 12;
C = importdata(filename,delimiterIn,headerlinesIn);
%To assign certain columns to a specific variable
tdump85072712 = C.data(:,9:12);
I then go on to plot each onto a map.
figure
lima ('xy') %Plots a stereographic map
plotps(tdump85072506(:,2),tdump85072506(:,3),'r-')
plotps(tdump85072512(:,2),tdump85072512(:,3),'color', [0 .498 0],'linestyle','-')
plotps(tdump85072518(:,2),tdump85072518(:,3),'k-')
plotps(tdump85072600(:,2),tdump85072600(:,3),'color', [.306 .396 .58],'linestyle','-')
plotps(tdump85072606(:,2),tdump85072606(:,3),'m-')
plotps(tdump85072612(:,2),tdump85072612(:,3),'b-')
plotps(tdump85072618(:,2),tdump85072618(:,3),'y-')
...
Does anyone know of an easier way to achieve the same thing?
  4 个评论
jonas
jonas 2018-7-24
It was a genuine question with a simple fix :)
C G
C G 2018-7-24
Oh, I didn't mean to offend. I figured I would get some mocking for being a newbee at matlab coding. I am grateful for any help I can get that will make my life easier when making all of these maps.

请先登录,再进行评论。

采纳的回答

Pawel Jastrzebski
Pawel Jastrzebski 2018-7-24
This is roughly how I would go about this problem [code untested]:
% Get all the file names in the folder
filename = dir('*.xlsx');
% Import settings
delimiterIn = ' ';
headerlinesIn = 12;
% empty Table that will hold ALL imported data
tData = []
% Use 'for loop' to import alle the data into one place
for i = 1:numel(filename)
C = importdata(filename,delimiterIn,headerlinesIn);
% add data to a table - 4 columns
tData = [tData C.data(:,9:12)]
end
% plot first set of data
figure
plotps(tData.(2),tData(3))
hold on
% add rest of the plots to the figure
% using 'for' loop
% starting from 2nd set of data
for j = 6:4:size(tData,2)
plotps(tData.(j),tData(j+1));
end
Side note, it's interesting to see that you import 4 columns out each file (columns 9:12) and yet use only column 2:3 from each data set for plotting. Are you using the remaining data for something else? If not just don't import it.
  6 个评论
Pawel Jastrzebski
Pawel Jastrzebski 2018-7-25
OK, I've fixed my original code and this import should work:
% Get all the file names in the folder
filename = dir('*.txt'); % STRUCT
filename = {filename.name}; % CELL
% Import settings
delimiterIn = ' ';
headerlinesIn = 12;
% empty Table that will hold ALL imported data
tData = []
% Use 'for loop' to import alle the data into one place
for i = 1:numel(filename)
C = importdata(filename{i},delimiterIn,headerlinesIn);
% add data to a table - 4 columns
tData = [tData C.data(:,9:12)];
end
clearvars delimiterIn headerlinesIn i C
And that's the output from in mt Matlab:
C G
C G 2018-7-25
Thank you! I am now on my way to creating lots and lots of maps for my thesis.

请先登录,再进行评论。

更多回答(1 个)

C G
C G 2018-7-25
编辑:C G 2018-7-25
After a few minutes of tinkering, I got this to work. Please let me know what you think. Still having trouble with the import step, so this was done manually.
%Step 1: Import your file names as a string. This step was done manually.
%Gets rid of the ugly header.
delimiterIn = ' ';
headerlinesIn = 12;
%Create an empty Table that will hold ALL imported data
tData = [];
% Use 'for loop' to import all of the data into one place
for i = 1:100
%Set this to the number of files you want to import. tdumpnamesS2 is my string name
C = importdata(tdumpnamesS2(i),delimiterIn,headerlinesIn);
%add data to a table - 4 columns
tData = [tData C.data(:,9:12)];
end
%plot first set of data
figure
lima('xy') %Plots a stereographic LIMA image of AA, full continent.
plotps(-71.166889,111.366531,'color', [.6 .2 1],'linestyle','none','marker','p','markersize',05, 'markerface',[.6 .2 1])
%The line above marks the end point for all of the trajectories.
plotps(tData(:,2),tData(:,3),'r-'); %Turns the first line red.
hold on;
%add rest of the plots to the figure using 'for' loop
%starting from 2nd set of data
for j = 6:4:size(tData,2)
plotps(tData(:,j),tData(:,j+1));
end

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by