Output at GUI
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
For my university project, i need to compile a programming for huffman coding algorithm. At the moment i have 2 main codes (.m files). one is GUI's m file and other is main program's m file. GUI's m file ask user input code and as soon as start button is pressed, the code is transferred to main program's m file where is completes whole task. The code for now is displaying output in matlab where as output is needed to be displayed in GUI. Can anybody please guide how to show the output in GUI. Following are the code.
%%%%%%%%---- GUI ----------%%%%%%%%%
function CODE_Callback(hObject, eventdata, handles)
data=get(hObject,'String');
input(data); %%transfer data to push button
% --- Executes on button press in START.
function START_Callback(hObject, eventdata, handles)
function input(data)
huff (data); %%calls main huff function
Main program code is
%%%%%%%----- MAIN PROGRAM --------%%%%%%%%
function huff(data) %%data from GUI
clc;
%fid=fopen('seq.txt','r');
seq5=data;
%seq=fread(fid,'*char');
%fclose(fid);
seq5=reshape(seq5,1,length(seq5));
testing(seq5);
[alpha prob]=probmodel(seq)
if ~isempty(alpha)
[huf entropy avglength redundancy]=huffman(alpha,prob);
if ~isempty(huf)
lp=length(prob);
for i=1:lp
str=huf(i).sym;
str=strcat(str,' :');
str=strcat(str,num2str(huf(i).prob));
str=strcat(str,' :');
str=strcat(str,huf(i).code);
disp(str);
end
disp(strcat('Entropy = ',num2str(entropy)));
disp(strcat('Average length = ',num2str(avglength)));
disp(strcat('Redundancy = ',num2str(redundancy)));
encseq=huffencode(huf,seq);
disp('Sequence :');
disp(seq);
disp('Encoded Sequence :');
disp(encseq);
decseq=huffdecode(huf,encseq);
disp('Decoded Sequence :');
disp(decseq);
end
else
display('Empty Sequence....');
end
end
Above program is working fine and displaying output in matlab. Only output to GUI file is needed. Also have created a static text in GUI and tagged with "OP" for displaying output.
Any help will be highly appreciated. Thanks in advance.
0 Commenti
Risposte (2)
Jakob Sørensen
il 24 Apr 2012
You can call functions from you GUI just like you normally would, but with one exception. You need to pass the handles as well, since that's where the GUI stores everything. So without getting too specific, here is how you get data from your GUI, to and external function, and back again:
% Lets say you have a var called 'data' that needs to be proccessed:
handles.data = data;
% And you have a function called 'some_function'
handles.output = some_function(handles.data)
% Now show it in, lets say a static text
set(handles.staticTextName, 'String,' handles.output);
% And to update the handles
guidata(gcbo, handles);
(And I just realised that I made an example where the entire handles thing werent nessesary, but it's a good way to do stuff, if you want to make sure where your data is.)
Jakob Sørensen
il 27 Apr 2012
In that case, you need to clarify something for me, since I can't see your GUI...
- How exactly does you GUI work? Is it a text field input and a submit button, or how?
- What do you want the external function to do? Does it calculate something and return it to the GUI? Or does it plot it right away?
- What input and output do you have from the external function.
0 Commenti
Vedere anche
Categorie
Scopri di più su Environment and Settings in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!