GUI briefly loading "old" data into graphs upon program initialization

Hi. I have a program that runs through a GUI. When the program loads there is a brief period when it appears to be loading "old" data into figures/graphs. This old data at one point in time had been fed into the program during development. This data was pulled from an external file and then graphed, so I am not sure how it still "remembers" it as the file is no longer in the same directory as the current GUI files. I have the same issue with an old logo that was read from a png file - when the program loads for a second or so the old logo still shows up before all the graphs/figures clear and the current logo loads. Any ideas how to remove this issue? Not sure if pictures will really help, but can provide if needed. thanks! h

 Accepted Answer

The data was in the figure at the time you saved the .fig file, so it will be replotted as the GUI is reinitialized.
You should go back into GUIDE and edit the properties of those axes and save the fig.

11 Comments

Thank you for the reply - can you point me towards what property I have to specifically edit? thanks! h
Look at the property XData (and YData and ZData) for most graphics, but look at the property CData for images.
I do not see XData, YData, Zdata, or CData in the property inspector.
Im obviously doing something wrong...
Axes do not have those properties. You should look at the children of the axes such as lineseries or image objects.
Would it be possible for you to attach your code and fig file? If that is too sensitive then perhaps if you edit the code down to the CreateFcn and OpenFcn callbacks for posting purposes?
I cant post the GUI but this is the opening function:
For simplicity have 2 axes, logo_axes which loads a image file, and axes_1 which plots data in a 2D graph
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI (see VARARGIN)
% Choose default command line output for GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% Clear all axes
cla(handles.axis_1)
cla(handles.logo_axis)
% Load logo
axes(handles.logo_axis)
logo = imread ('logo.bmp');
imshow(logo);
There is no code for any of the axes CreateFcn
If i don't clear the axes the old data just persists until i do something else with the GUI (load new data etc).
Thank you for the help...this is driving me crazy!
Okay, in the fig file, use GUIDE to delete the children of axis_1 and logo_axis and then save (I recommend saving to a different name and testing with that first.)
thanks. Can you give me more specifics on how to do this via GUIDE? I know how to do with code from within the .m file that links to the GUI fig, but not how to do via Guide.
thanks!
Hmmmm...
If you load the code in GUIDE, and then run the GUI, and then at the command line,
handles = guidata(gcf);
cla(handles.axis_1)
cla(handles.logo_axis)
and then save in GUIDE (I recommend saving to a different name for testing) then I think that might do it.
Hi. I tried that but it did not work. the first line of code opens a new blank figure, and with the second and third lines I get this error
Struct contents reference from a non-struct array object.|
Any other ideas?
thx!
fig = GUI;
handles = guidata(fig);
cla(handles.axis_1);
cla(handles.logo_axis);
so I ended up just deleting and re-inserting the axes again and now they work without the old data showing up on initialization. Not sure why wasn't working before but seems to be working now. thanks again for all of your help!

Sign in to comment.

More Answers (1)

Hey, I'm glad that you could solve the problem. Yesterday it happened the same to me and I saw this post and could solve it too. However, in my gui, I had the "Save" button, as well as the "Zoom" and the "hand". I accidentaly clicked on the Save button of the GUI instead of the Save button in the .fig file that contains the GUI design. Then, everything changed and started to load old data, the same data that was on the GUI when I clicked on that Save Button. Then, in order to solve it I had to reset the axes from the .m file and then click again on that Save button. This is because as the .fig file did change, then I could not solve it from there. The error source was on the GUI that calls the GUI.m file, so that should be solved from there, instead than from the .fig file. Its tricky...
Also, if you have any plot in your axes, then when reset and saving again, these axes will change their tag, so you have to put the tags again from the .fig file. Then is fine!
Hope this non-obvious error and solution can help other people. And remember to NOT include the Save button into the GUI haha

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!