Separating an array into multiple, unequal sized arrays using a limiter
7 views (last 30 days)
Show older comments
I have a file containing lat/lon coordinates and am trying to separate this large array (>70000 lines) into separate arrays each of less than 1500 lines per. However, if I find a "NaN" values within this array, it has to use this as its limiting agent rather than the 1500 lines.
Eg. If NaN occurs before 1500 lines are read, separate by (1:NaN)x2. If no NaN is read within 1500 values, separate the file in 1500x2.
Example of my array:
46.877355, 303.534205
46.799428, 303.237852
46.690925, 303.632512
46.614782, 303.645623
NaN, NaN
46.494857, 303.361513
46.418715, 303.563425
NaN, NaN
46.361608, 303.764633
46.287368, 303.635356
46.249297, 303.245622
46.237876, 303.876536
Im looking for some help on the code to complete this, so that in the end (for the example file), it would have one array that is 4x2, the next would be 2x2 and the last would be 4x2.
This is what I have so far.
poly01 = [lat(1:index_nan(1)-1),lon((1:index_nan(1)-1))];
k = 1;
for s = 1:1500:length(poly01(:,1));
if s+1500-1 > length(poly01(:,1));
seg_poly{k} = poly01(s:end,:);
else
seg_poly{k} = poly01(s:s+1500-1,:);
end;
k=k+1;
end;
Once the code
poly01 = [lat(1:index_nan(1)-1),lon((1:index_nan(1)-1))];
hits a NaN however, it stops writing and only prints the first 4 lines of the above array.
Thank you in advance, Shannon
0 Comments
Answers (1)
Sean de Wolski
on 18 Dec 2015
Edited: Sean de Wolski
on 18 Dec 2015
x = your_array
cx = polysplit(x(:,1),x(:,2))
cx =
[4x1 double]
[2x1 double]
[4x1 double]
After this could go through and further split any cell with more than 1500 rows.
0 Comments
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!