Reputation: 25
I have created a GUI in matlab with few buttons. Each button when clicked performs a certain function. Now I want to display the calculations being performed in the function to be displayed in a static textbox in the GUI. Is that possible? I am able to display it in the command window by removing the semicolon (;) at the end of the statement but I want it to be displayed in the GUI like a log.
Now when I click the "match" button the following function is called and I want to display whether it matches or not in the GUI in a textbox. Is that possible?
function matchin
[image1, pathname]= uigetfile('*.bmp','Open An image');
Directory = fullfile ('F:','matlab','bin');
D = dir(fullfile(Directory,'*.bmp'));
%imcell = {D.name}';
for i = 1:numel(D)
if strcmp(image1,D(i).name)
disp('matched');
else
disp('not matched');
end
end;
I replaced the code with the one specified in the answer. Without using the text box the output in the matlab command window when I select the second file is
not matched
matched
not matched
not matched
not matched
But if I use a static textbox only the last line is being displayed. How can I display all the 5 lines totally?
Upvotes: 1
Views: 816
Reputation: 699
Yes, you can do that.
A good practice would be to save a structure with all the handles of your GUI elements by using the function guidata. For more information on this see this link.
Then in your callback you can retrieve this structure, for instance by:
handles = guidata(gcbo);
Then you can set the value of the textbox you want by replacing
if strcmp(image1,D(i).name)
disp('matched');
else
disp('not matched');
end
with:
if strcmp(image1,D(i).name)
set(handles.handle_of_textbox,'String','matched');
else
set(handles.handle_of_textbox,'String','not matched');
end
Upvotes: 2