Info
This question is closed. Reopen it to edit or answer.
How to stop my matrix populating cells with a zero?
2 views (last 30 days)
Show older comments
Hi All, i currently have a ascii text file that contains four columns these columns represent a latitude, longitude, ellipsoid separation value and a error value. I am only interested in the first 3. below is and example of the data set,but its allot bigger roughly 180,000 rows of seperation at varying latitudes and logitudal positions.
55.9920 000.0000 44.2537 0.1221
55.9920 000.0080 44.2454 0.1221
55.9920 000.0160 44.2373 0.1221
55.9920 000.0240 44.2301 0.1221
55.9920 000.0320 44.2235 0.1221
55.9920 000.0400 44.2164 0.1221
55.9920 000.0480 44.2089 0.1221
55.9920 000.0560 44.2010 0.1221
55.9920 000.0640 44.1932 0.1221
55.9920 000.0720 44.1861 0.1221..
I am creating a model to interpolate the separation value for any input Lat and lon, firstly i must change the layout of the ascci file so i am using the following script:
% Initialise the array difining the start locations of each variable
Ulat=unique(D(:,1)); % The first column unigue latitude values
Ulon=unique(D(:,2)); % Ditto, second
% Change the layout of a Ascii file to a matrix, allows for the formation % of a ellipsodal seperation model
N1=length(Ulat);
N2=length(Ulon);
S=zeros(N1+1,N2+1);
S(1,2:end)=Ulon;
S(2:end,1)=Ulat;
% correlate the locations in the original table with their location in the new. % An easy way to generate the lookup table is...
[~,ix1]=histc(D(:,1),Ulat); % the bin for each unique value in
[~,ix2]=histc(D(:,2),Ulon); % new array
% Turn the above values into locations for the new array...
ix=sub2ind(size(S),ix1+1, ix2+1); % bin subscripts to linear indices
S(ix)=D(:,3); % and store..
This all works very well on some of the data set ive used before, but with this current one it seems to be populating the separation values in places with zeros and not indexing in the original values associated with those positions from the original text file, as each position has a separation value in the original text doc i cant see why there are now positions with a 0 separation value?
I hope this make sence and any help that can be offered will be much appreciated
ps to interp the separation from the modle i am using the
result = interp2(lon,lat,sep,lon1,lat1,'cubic');
After defining the variable of both the model and the input arguments.
Regards Gavin
4 Comments
dpb
on 19 Feb 2014
Edited: dpb
on 19 Feb 2014
I thought that looked somewhat familiar but wasn't positive you were the previous poster or not but some of the comments had a "dpb-ish" flavor to them and now I do recall the moniker... :)
In this case there's not necessarily any way to do the rearrangement without having some missing values on a complete grid--there just aren't going to be values in some locations. I don't think it's even guaranteed that anything excepting a very coarse averaging would be certain to do, either.
In my previous response I was thinking of a roundoff/precision thing of perhaps having generated a set of coordinates by two separate processes that were intended to be identical but owing to that precision weren't. Your data are actually different but the hole comes simply because they aren't on a regular grid as the previous solution assumes/requires.
I don't recollect enough about the problem to know what to tell you is the solution. Perhaps you could use one of the other gridding techniques such as DelaunayTri? Or, instead of zeros use nan as the initialization and write the downstream processing to treat NaN as missing values?
Answers (0)
This question is closed.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!