interpolation issues and errors in GUI
1 次查看(过去 30 天)
显示 更早的评论
So I have this GUI... a section has a user input area where they put in a series of lat, lon, alt and then specify number of points they want between each value. I have managed to get this interpolation button sorta working in 2 different ways .
Here are over simplified sample lats entered:
5 , 42, 22, 30
and I gave 'interp' a value of 2
Here is the opening of my interpolation function
function interpbtn_Callback(hObject, eventdata, handles)
lla = getappdata(0, 'lla') % this is lat, lon, alt data user entered in prev callback
intrp = str2double(get(handles.interpolateer,'String')) % this is # of points user wants interpolated
lat =lla(:,1)
lon =lla(:,2)
alt =lla(:,3)
First sorta working method is using the interp1 function
L = numel(lat);
x = 1:L;
xp = linspace(1, L, intrp *(L-1) + intrp );
out = interp1(x, lat, xp)
jj = union(lat,out)
The problem here is the 'out' gives me all the interpolated values but leaves out the entered numbers. so I union them. now they are all in order which I don't want. Enter a number higher than 4 for intrp and you get more than requested interp points !!!
out = 5.0000 20.8571 36.7143 36.2857 27.7143 23.1429 26.5714 30.0000
jj =
5.0000
20.8571
22.0000
23.1429
26.5714
27.7143
30.0000
36.2857
36.7143
42.0000
So I try a new method..... I use a for loop and linespace (I initialized handles.latnew =[]; in gui start up)
for i= 1:length (lat)
handles.latnew = [handles.latnew;linspace(lat(i,1), lat((i+1),1), intrp+2)'];
guidata( hObject, handles );
handles.latnew;
setappdata(0,'llaintrpE2',handles.latnew);
end
here is I get almost exactly what I wanted but a double up of values..
5.0000
17.3333
29.6667
42.0000
42.0000 <--- ugh
35.3333
28.6667
22.0000
22.0000 <--- ugh again
24.6667
27.3333
30.0000
I also get a nasty Matlab message every time:
Index exceeds matrix dimensions.
Error in TOOL>interpbtn_Callback (line 727)
handles.latnew = [handles.latnew;linspace(lat(i,1), lat((i+1),1), intrp+2)'];
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in TOOL (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)TOOL('interpbtn_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
I've been reworking these two methods trying to get them to work for several days now. and this is the closest I've been able to get using both methods. I can't figure out how to tell first method to stop putting in order and why does it give me more interpolated points than what I requested when I request anything more than 4. I can't figure out how to tell second method to leave out duplicates or why I'm getting error message.
help me !
1 个评论
Greg
2018-1-18
编辑:Greg
2018-1-18
It's also giving you exactly what you asked for.
xp = linspace(1, L, intrp *(L-1) + intrp );
% xp ends up being 8 values
% 2*(4-1) + 2 = 8
jj = union(lat,out);
% jj is now 10 values, assuming there are 2 duplicates in lat and out
Finally,
for i= 1:length (lat) % <-- the last iteration of the loop is the maximum index of lat
handles.latnew = [handles.latnew;linspace(lat(i,1), ...
lat((i+1),1), ... % <-- You now add 1 to the max index of lat, it better throw Index exceeds matrix dimensions.
intrp+2)'];
回答(2 个)
Greg
2018-1-18
编辑:Greg
2018-1-18
Edit: I must apologize. I said setdiff below and I meant unique.
You've already found the union function. Scroll to the bottom of the documentation page and check out the other set operations in the See Also section. Specifically, setdiff will help you with method 2, after you fix the other things (sorting and loop index) per my comment above.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interpolation of 2-D Selections in 3-D Grids 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!