当前位置:网站首页>Matlab implementation of Huffman coding and decoding with GUI interface
Matlab implementation of Huffman coding and decoding with GUI interface
2022-07-07 11:49:00 【Matlab scientific research studio】
1 brief introduction
stay matlab Middle simulation C Middle linked list , Using complex number operation , Contact specific characters and probabilities , Find the number corresponding to the two characters of the minimum probability each time , Record it in turn , Finally, according to the different implementation of parity codes Huffman code . This algorithm is novel and unique , Easy to understand , Programming .
2 Part of the code
function varargout = huffman_GUI(varargin)
% HUFFMAN_GUI M-file for huffman_GUI.fig
% HUFFMAN_GUI, by itself, creates a new HUFFMAN_GUI or raises the existing
% singleton*.
%
% H = HUFFMAN_GUI returns the handle to a new HUFFMAN_GUI or the handle to
% the existing singleton*.
%
% HUFFMAN_GUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HUFFMAN_GUI.M with the given input arguments.
%
% HUFFMAN_GUI('Property','Value',...) creates a new HUFFMAN_GUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before huffman_GUI_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to huffman_GUI_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help huffman_GUI
% Last Modified by GUIDE v2.5 10-Jan-2014 18:20:43
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @huffman_GUI_OpeningFcn, ...
'gui_OutputFcn', @huffman_GUI_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin & isstr(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before huffman_GUI is made visible.
function huffman_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 huffman_GUI (see VARARGIN)
% Choose default command line output for huffman_GUI
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes huffman_GUI wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = huffman_GUI_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes during object creation, after setting all properties.
function xylj_CreateFcn(hObject, eventdata, handles)
% hObject handle to xylj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function xylj_Callback(hObject, eventdata, handles)
% hObject handle to xylj (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of xylj as text
% str2double(get(hObject,'String')) returns contents of xylj as a double
% --- Executes on button press in dqxy.
function dqxy_Callback(hObject, eventdata, handles)
% hObject handle to dqxy (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[Filename Pathname]=uigetfile({'*.txt'},' Please select a file '); % Select the file box function
str=[Pathname Filename]; % Get the path and file name
xinyuan=textread(str,'%s'); % In the form of strings , Read in a text file
xinyuan=xinyuan{:}; % take cell Type data into char
set(handles.xylj,'string',str) % Show the path of the source
set(handles.xy,'string',xinyuan) % Show source
% --- Executes during object creation, after setting all properties.
function xy_CreateFcn(hObject, eventdata, handles)
% hObject handle to xy (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function xy_Callback(hObject, eventdata, handles)
% hObject handle to xy (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of xy as text
% str2double(get(hObject,'String')) returns contents of xy as a double
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in bm.
function bm_Callback(hObject, eventdata, handles)
% hObject handle to bm (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc; % eliminate command window
data=get(handles.xy,'String'); % Read into the source
data=uint8(data); % Convert the source into uint8
[codeword_OK,simbolsout1,fout1,simbolsout2,fout2,zipped,info] = norm2huff(data); % code
% Before ordering
for i=1:length(fout1)
fout1str{i}=num2str(fout1(i)); % Convert the probability before sorting into cell Type data , convenient listbox Use
str1{i}=char(simbolsout1(i)-1); % Convert the symbols before sorting into cell Type data , convenient listbox Use ,char take ASCII Code to character
end
handles.str1=str1; % Get the pre sort symbol
handles.fout1str=fout1str; % Get the pre ranking probability
% After ordering
for i=1:length(fout2)
str2{i}=char(simbolsout2(i)-1); % Convert the sorted symbols into cell Type data , convenient listbox Use ,char take ASCII Code to character
end
handles.str2=str2; % Get the sorted symbols
% Get the code
for i=1:length(codeword_OK)
codestr{i}=num2str(double(codeword_OK{i}));
codestr{i}=codestr{i}(find(codestr{i}~=' ')); % Remove the spaces in the string , Get Hoffman code
end
handles.codestr=codestr; % Save Hoffman code
handles.zipped=zipped; % Save the encoded results
handles.info=info;
guidata(hObject, handles); % to update handles Structure
% --- Executes on button press in myzl.
function myzl_Callback(hObject, eventdata, handles)
% hObject handle to myzl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
set(handles.xsmyzl,'Value',1)
set(handles.xsmyzl,'String',handles.str1);
% --- Executes during object creation, after setting all properties.
function xsmyzl_CreateFcn(hObject, eventdata, handles)
% hObject handle to xsmyzl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
% --- Executes on selection change in xsmyzl.
function xsmyzl_Callback(hObject, eventdata, handles)
% hObject handle to xsmyzl (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns xsmyzl contents as cell array
% contents{get(hObject,'Value')} returns selected item from xsmyzl
error('input argument must be a uint8 vector')
end
%f=repmat(0,1,256);
% Scan vector
len=length(vector);
for index=0:255; % Note that the index parameter of the vector is from 0 At the beginning
f(index+1)=sum(vector==uint8(index));
end
%
3 Simulation results
4 reference
[1] Wu Jiqun , Li shuangke . Matlab achieve huffman code [J]. China Science and technology information , 2006(19):2.
About bloggers : Good at intelligent optimization algorithms 、 Neural networks predict 、 signal processing 、 Cellular automata 、 The image processing 、 Path planning 、 UAV and other fields Matlab Simulation , relevant matlab Code problems can be exchanged by private letter .
Some theories cite network literature , If there is infringement, contact the blogger to delete .
边栏推荐
- R Language Using Image of magick package Mosaic Function and Image La fonction flatten empile plusieurs images ensemble pour former des couches empilées sur chaque autre
- R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
- Tsinghua Yaoban programmers, online marriage was scolded?
- 【滤波跟踪】基于matlab捷联惯导仿真【含Matlab源码 1935期】
- When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
- 相机标定(2): 单目相机标定总结
- 0.96 inch IIC LCD driver based on stc8g1k08
- 【愚公系列】2022年7月 Go教学课程 005-变量
- Flet教程之 15 GridView 基础入门(教程含源码)
- 深度学习秋招面试题集锦(一)
猜你喜欢
Verilog design responder [with source code]
聊聊SOC启动(六)uboot启动流程二
About how to install mysql8.0 on the cloud server (Tencent cloud here) and enable local remote connection
使用MeterSphere让你的测试工作持续高效
清华姚班程序员,网上征婚被骂?
Summed up 200 Classic machine learning interview questions (with reference answers)
CMU15445 (Fall 2019) 之 Project#2 - Hash Table 详解
分布式数据库主从配置(MySQL)
【系统设计】指标监控和告警系统
Talk about SOC startup (x) kernel startup pilot knowledge
随机推荐
Suggestions on one-stop development of testing life
STM32 entry development write DS18B20 temperature sensor driver (read ambient temperature, support cascade)
When sink is consumed in mysql, the self incrementing primary key has been set in the database table. How to operate in Flink?
Onedns helps college industry network security
聊聊SOC启动(六)uboot启动流程二
R语言使用magick包的image_mosaic函数和image_flatten函数把多张图片堆叠在一起形成堆叠组合图像(Stack layers on top of each other)
Easyui学习整理笔记
本地navicat连接liunx下的oracle报权限不足
Various uses of vim are very practical. I learned and summarized them in my work
《通信软件开发与应用》课程结业报告
LeetCode - 面试题17.24 最大子矩阵
Learning notes | data Xiaobai uses dataease to make a large data screen
What is cloud computing?
相机标定(2): 单目相机标定总结
[filter tracking] strapdown inertial navigation simulation based on MATLAB [including Matlab source code 1935]
R language uses the quantile function to calculate the quantile of the score value (20%, 40%, 60%, 80%), uses the logical operator to encode the corresponding quantile interval (quantile) into the cla
聊聊SOC启动(七) uboot启动流程三
In SQL, I want to set foreign keys. Why is this problem
Flet教程之 17 Card卡片组件 基础入门(教程含源码)
How much do you know about excel formula?