1

I have the following code which is a graphic rendering of the movement of a satellite around the Earth.

function ex
global state;
fh = figure('Menu','none','Toolbar','none','Units','characters');
hPanAni = uipanel('parent',fh,'Units','characters','Position',...
    [22.6 10.4 53 23],'title','Controls','FontSize',11,...
    'FontAngle','italic','FontWeight','bold');
hIniAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
    'Position',[0.14 0.75 0.5 0.12],'String','Spin',...
    'FontSize',10,'Callback',@hIniAniCallback);
hFinAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
    'Position',[0.14 0.5 0.5 0.12],'String','Stop',...
    'FontSize',10,'Callback',@hFinAniCallback);
hResetAni = uicontrol(hPanAni,'Style','pushbutton','Units','normalized',...
    'Position',[0.14 0.25 0.5 0.12],'String','Reset',...
    'FontSize',10,'Callback',@hResetAniCallback);
hPantSim = uipanel('Parent',fh,'Units','characters',...
    'Position',[107.87 8 157.447 42],'BorderType','none','title',...
    'Screen','FontSize',11,'FontAngle','italic',...
    'FontWeight','bold');
hPantSimInt = uipanel('Parent',hPantSim,'Units','normalized','Position',...
    [0 0 1 1],'BorderType','line','BackgroundColor','black');
ah4 = axes('Parent',hPantSimInt,'Units','normalized','Position',...
    [0 0 1 1],'Color','none','Visible','off','DataAspectRatio',...
    [1 1 1],'NextPlot','add');
rotate3d(ah4);
hgrot = hgtransform('Parent',ah4);
T1 = 0:pi/100:2*pi;
Y = zeros(numel(T1),3);
Y(:,1) = 7000*cos(T1);
Y(:,2) = 7000*sin(T1);
xmin = min(Y(:,1));
ymin = min(Y(:,2));
zmin  = min(Y(:,3));
xmax  = max(Y(:,1));
ymax  = max(Y(:,2));
zmax  = max(Y(:,3));
Resf = 6378;
xmin2 = min(xmin,-Resf);
xmax2  = max(xmax,Resf);
ymin2 = min(ymin,-Resf);
ymax2  = max(ymax,Resf);
zmin2  = min(zmin,-Resf);
zmax2  = max(zmax,Resf);
set(ah4,'XLim',[xmin2 xmax2],'YLim',[ymin2 ymax2],'ZLim',[zmin2 zmax2]);
maptext = imread('tierra.jpg');
[X_im, map] = rgb2ind(maptext,128);
[x_esf,y_esf,z_esf] = sphere(50);
x_esf = Resf*x_esf;
y_esf = Resf*y_esf;
z_esf = Resf*z_esf;
props.FaceColor= 'texture';
props.EdgeColor = 'none';
props.Parent = hgrot;
props.Cdata = flipud(X_im); % it is necesary to do this for getting the 
% appropiate image on the sphere
surface(x_esf,y_esf,z_esf,props);
colormap(map);
axis equal vis3d;
view(3);
az = 0;
Fin = numel(T1);
k = 2;
ind_ini = 0;
state = 0;
handles.tray = zeros(1,Fin);
handles.psat = line('parent',ah4,'XData',Y(1,1), 'YData',Y(1,2),...
    'ZData',Y(1,3),'Marker','o', 'MarkerSize',10,'MarkerFaceColor','b');
       function hIniAniCallback(hObject,evt)
            if (ind_ini == 1)
              return;  
            end
            ind_ini = 1;
            state = 0;
            while (k<Fin)
            az = az + 0.01745329252;
            set(hgrot,'Matrix',makehgtform('zrotate',az));
            handles.tray(k) = line([Y(k-1,1) Y(k,1)],[Y(k-1,2) Y(k,2)],...
                [Y(k-1,3) Y(k,3)],...
        'Color','red','LineWidth',3);
            set(handles.psat,'XData',Y(k,1),'YData',Y(k,2),'ZData',Y(k,3));
            pause(0.02); 
            k = k + 1,

            if (state == 1)
                state = 0;
                break;
            end
            end 
       end

    function hFinAniCallback(hObject,evt)
        ind_ini = 0;
        state = 1;
    end
 function hResetAniCallback(hObject,evt)
    set([handles.tray,handles.psat],'Visible','off');
    k = 2;
    ind_ini = 0;
    state = 1;
    az = 0;
    set(hgrot,'Matrix',makehgtform('zrotate',az));
    handles.psat = line('parent',ah4,'XData',Y(1,1), 'YData',Y(1,2),...
    'ZData',Y(1,3),'Marker','o', 'MarkerSize',10,'MarkerFaceColor','b');
end

end

However, when I copy it to my main program I get the following error message:

??? Error using ==> surface
Invalid object handle

Error in ==> simorbiv8v3>hIniPropCallback at 1911
surface(x_esf,y_esf,z_esf,props);

??? Error while evaluating uicontrol Callback

EDIT: After some proofs, I have checked that ishandle(props.Parent) is false. As props.Parent = hgrot, the problem source is this hgtransform variable. It is declared as global one in the main program so there should not be problems then. I do not understand what is wrong with hgrot.

julianfperez
  • 1,726
  • 5
  • 38
  • 69
  • I doubt anyone is going to read through all of that code. Isolate what's causing the error and remove everything else, and then people can help you. – Phonon Dec 24 '11 at 02:26
  • Second Phonon there is a lot extra information here. – Stefan Gretar Dec 24 '11 at 02:31
  • @Phonon: I think the code is necessary to understand my problem. I might have written that I get a message error with the command line `surface(x_esf,y_esf,z_esf,props);` and then write it but that would not be very useful. – julianfperez Dec 24 '11 at 09:59
  • @stefangretar: Sometimes is better extra information than a lack of it. – julianfperez Dec 24 '11 at 10:00

2 Answers2

1

I suspect this is for a Matlab GUI?

If so you need to pass the handles variable to the script, normally matlab passes eventdata and hObject as well as a standard procedure for all functions, callbacks and etc.

function ex(hObject, eventdata, handles)

And don't forget to update the GUI data to close the function.

guidata(hObject,handles);

I think all your nested functions that use the handles structure are going to require this as well.

Hope this helps.

Stefan Gretar
  • 178
  • 1
  • 10
0

Finally, I have found that there was a cla command line, which was the guilty of the error, in the main program.

julianfperez
  • 1,726
  • 5
  • 38
  • 69