Is it a bug in GUIDE?

I am trying to run some lines of code that run perfectly in m-script. The code is long and I can not paste it here. My point is that why MATLAB GUI does not run the script as the normal m-script. I am working on a project based on Sudoku based image steganography, in which I have successfully programed the project in m-script, but when I try to incorporate the code in MATLAB GUI script, it's not working the way it worked in normal m-script. Is it a bug?
NOTE - I have checked all the handles and GUI objects. There is no error in them.

回答(1 个)

Walter Roberson
Walter Roberson 2016-3-10

0 个投票

GUIDE does not program in terms of scripts. GUIDE programs in terms of functions. All the callbacks you code will be in functions. Scripts typically run in the base workspace, but functions run in their own workspace, and would have to specifically ask for variables in the base workspace and would have to specifically write to the base workspace to store variables if it wanted to do that.

6 个评论

clc;
clearvars -except O1 O2 O3 O4 S mat;
[X,Y]=size(O3);
Oo3=reshape(O3',[X*Y,1]);
i=1;
for j=1:(length(Oo3))/2
p(i,1)=Oo3(2*j-1);
p(i,2)=Oo3(2*j);
i=i+1;
end
[X,Y]=size(O4);
Oo4=reshape(O4',[X*Y,1]);
i=1;
for j=1:(length(Oo4))/2
q(i,1)=Oo4(2*j-1);
q(i,2)=Oo4(2*j);
i=i+1;
end
%%Code to Reconstruct the Secret Image from the Shadow Images O3 and O4.
i=1;
l=1;
while i<=length(p)
a1=mat(uint8(p(i,1)),uint8(p(i,2)));
a2=mat(uint8(q(i,1)),uint8(q(i,2)));
a=strcat(dec2bin(a1,4),dec2bin(a2,4));
A=bin2dec(a);
Sj(l)=A;
i=i+2;
l=l+1;
end
rec=reshape(Sj',[256,256]);
rec=uint8(rec');
S=uint8(S);
%%Viewing the Reconstructed Image
figure(2);
subplot(121);imshow(S);title('Secret Image');
imshow(rec);title('Recovered Image');
GUI code =>
function reconstructsecret_Callback(hObject, eventdata, handles)
% hObject handle to reconstructsecret (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cla(handles.axes6);
mat=handles.mat;
O3=handles.O3;
O4=handles.O4;
[X,Y]=size(O3);
Oo3=reshape(O3',[X*Y,1]);
i=1;
for j=1:(length(Oo3))/2
p(i,1)=Oo3(2*j-1);
p(i,2)=Oo3(2*j);
i=i+1;
end
[X,Y]=size(O4);
Oo4=reshape(O4',[X*Y,1]);
i=1;
for j=1:(length(Oo4))/2
q(i,1)=Oo4(2*j-1);
q(i,2)=Oo4(2*j);
i=i+1;
end
p=uint8(p);
q=uint8(q);
i=1;
l=1;
h = waitbar(0,'Decrypting Images, Please wait...');
while i<=length(p)
waitbar((i)/(length(p(:,1))-1))
disp(i);
a1=mat(p(i,1),p(i,2));
a2=mat(q(i,1),q(i,2));
a=strcat(dec2bin(a1,4),dec2bin(a2,4));
A=bin2dec(a);
Sj(l)=A;
i=i+2;
l=l+1;
end
delete(h)
rec=reshape(Sj',[256,256]);
rec=uint8(rec');
axes(handles.axes6);imshow(rec);
end
You are asking for various fields from the handles struct. Were these ever actually added to the struct? Do they come from the UI itself or are they expected to be from somewhere else?
UI itself.
And have you any code that puts these values into the handles structure?
If not you need to do something more like, for example
O3 = str2num( handles.editO3.String )
if you have an edit box with the tag 'editO3' in your UI. You should always change the 'Tag' for your UI components in GUIDE to something that is understandable rather than the defaults unless you enjoy the challenge of trying to remember what pushbutton27 and editbox12 are for! Note that that syntax only works for R2014B or later. If you are in an earlier version you have to use
O3 = str2num( get( handles.editO3, 'String' ) );
Thanks Adam - I didn't know that form of accessing the string content was now available.
Never mind. My MATLAB has started crashing when I try to open GUIDE. Let me have a look at it.
Thank you everyone for taking your time out for me.

此问题已关闭。

标签

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by