plot - plotting trajectories using matlab -


im matlab is trying to plot the interpolation path on my data file (try.txt) trajectory and looks like this:

  NumofTrajectories TrajID1 #ofPoints xyx y .... TrajID2 #ofPoints xyx y ....  

Example:

 < Code> 7 0 23 898.6 673.0 85 9.1 669.9 813.7 667.8 776.8 664.0 739.8 662.1 69 9.6 654.7 664.5 648.6 640.6 552.3 634.2 516.6 628.2 477.2 624.3 442.1 613.6 406.7 603.4 36 9.5 59 9.8 332.7 594.1 297.4 585.2 258.6 583.7 224.1 573.1 191.2 556.8 152.7 554.0 115.1 546.0 79.6 535.8 1 8 481,4 624,9 445,9 596,3 374,5 573,9 354,2 541,0 334,2 508,9 327,6 474,1 324,6 437,5 324,2 390 , 3 2 24 151,6 570,8 188,3 556,5 225,1 547,7 257,9 529,4292,9509,8 326,8 496,8 356,2 476,0391,2 463 , 3 423,7 447,9455,7 431,8 489,2 416,0 524,3405 , 3 560,0395,9 595,8 385,6 632,8 376,1 671,5 372,0 706,9 361,8 742,3 347,3 778,0 334,5 820,5 336,5 856,5 325,0 894,5 309,5 946,1 309,9 990,5 287,0 3 3 594,2 580,4 5 66,6 544,3 544,9 509,4 4 5 281,8 661,9 266,8 623,4 246,2 576,4 229,7 541,0 220,9 498,4 5 2 563,6 511,3 532,5 479,7 6 5 571,9 617,7 525 , 6 576,4 481,0 551,9 456,8 524,2 419,7 474,0  

I am trying to plot this kind of matab: clear; Read% input import file ('try.txt')% See how many number of trajectories number nTraj = str2num (convert to cell2mat (textdata)); % Loop on trajectories for I = 1: nTraj disp (data (i, 1)); Print the current trajectory number Disp (data (i, 2)) of% points; Get the x-y coordinate of every trajectory current_traj = data (i, 2); For J = 1: current_traj points = data (i, 3: j * 2 + 2); Print the X-Y coordinates of the end% of each trajectory% V (digit); X-y coordinate y = points (2: 2: length (number)) xlabel ('latitude') of each trajectory x = points (1: 2: length (digits) -1); Ylabel ('longitude'); Plot (x, y, 'r'); On the grid; Wait; End

and function importfile :

  function importfile (fileToRead1)% IMPORTFILE (FILETOREAD1) imports data from specified file %% FILETOREAD1: file to read DELIMITER = ''; HEADERLINES = 1; % File import newData1 = importdata (fileToRead1, DELIMITER, HEADERLINES); % Create new variables from those regions in the base workspace = = WARS = fieldname (new data1); For I = 1: Length (Wars) Assignment ('Base', Wars {i}, New Data 1. (Wars {i}); End code  

The code sometimes works and usually tells me an error:

  The index exceeds matrix dimensions. ==> In order to detect error plot 23 points = data (i, 3: j * 2 + 2); Can anyone explain the error and tell me how to fix it?  

trajectories in try.txt are different lengths import data will use the first line to determine the length of your data if the second row is the longest, then this line will split on several lines of your imported matrix. At least this is what shows debugging. I would recommend that you use another method to read your file dlmread works for me:

  Read% input data = dlmread ('try.txt', ''); % Header data = data (2: end, :); % See how many number of routes are converted to nTraj = size (data, 1);  

You can change your first line with this code and remove your importfile function.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -