edit text, push button and output.

조회 수: 3 (최근 30일)
Muhammad Taqi
Muhammad Taqi 2012년 4월 23일
Dear All, while working for my university project, am bit stuck in the final steps of GUI. Have compiled a code for Huffman coding. what my requirement is to get input from user which i am able to by creating GUI and placing edit text. Also am able to get entered text.
f unction CODE_Callback(hObject, eventdata, handles)
% hObject handle to CODE (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data=get(hObject,'String');
% Hints: get(hObject,'String') returns contents of CODE as text
% str2double(get(hObject,'String')) returns contents of CODE as a double
Now i need help to communicate entered text (variable named as "data") with start button to run the complete program. and also to show final output on GUI (text based output)
% --- Executes on button press in START.
function START_Callback(hObject, eventdata, handles)
% hObject handle to START (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
huff (data); % calling main program for huffman coding
-----%%%%%%-----------
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);
(Want to display all output on GUI)
Urgent help will be highly appreciated. Thanks in advance.
  댓글 수: 1
Muhammad Taqi
Muhammad Taqi 2012년 4월 23일
Wholla,,,, I managed to figure out my first query, did managed to make start button work.
Help regarding output is required.
thanks :)

댓글을 달려면 로그인하십시오.

답변 (2개)

Daniel Shub
Daniel Shub 2012년 4월 23일
If you make an additional text box on your gui you can then set the string of that text box to be str where
str = {
strcat('Entropy = ',num2str(entropy))
strcat('Average length = ',num2str(avglength))
strcat('Redundancy = ',num2str(redundancy))
...
}
  댓글 수: 7
Muhammad Taqi
Muhammad Taqi 2012년 4월 23일
So what should i do for the new function to work??
Daniel Shub
Daniel Shub 2012년 4월 24일
You need to read about how to create functions and guis in MATLAB.

댓글을 달려면 로그인하십시오.


Image Analyst
Image Analyst 2012년 4월 23일
Don't use disp() because that outputs to the command window. If you want it to go to your GUI, use set(). Lets say you have a static text control called txtInfo. Then you can use this code:
% Create string for output that we can send to the text control.
txtInfo = sprintf('Entropy = %.4f\nAverage length = %.4f\nRedundancy = %.4f', entropy, avglength, redundancy);
% Now, send the string to the control called txtInfo
set(handles.txtInfo, 'String', txtInfo);
If that is in a tight loop, you might also need to add a "drawnow" to get it to update immediately.
  댓글 수: 4
Muhammad Taqi
Muhammad Taqi 2012년 4월 24일
Well, if i replace disp() with set(), its still giving an error.
??? Undefined variable "handles" or class "handles.txtInfo".
Muhammad Taqi
Muhammad Taqi 2012년 4월 24일
Also, i tried creating an output function as
txtInfo = sprintf('Entropy = %.4f\nAverage length = %.4f\nRedundancy = %.4f', entropy, avglength, redundancy);
then i want to transfer that string to my GUI function for display.
How should i sent there?
Have named my GUI file as TEST2.
function varargout = TEST2(varargin)

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by