文本文档text保存如:
AAM air-to-air missile 空对空导弹
AMB antiballistic missile 反弹道导弹
AC alternating current 交流电
AEW airborne early warning 空中预先警报
Ag argentum 元素银
……
……
……
的形式,不好意思,我只会做这种形式的
生成gui的m程序:
function main_gui
clear;
h=figure('Units','normalized','Position',[0.3 0.3 0.45 0.35],'Color',[0.8,0.8,0.8],'Menubar','none', 'Resize','off');
set(h,'name','单词查询','numbertitle','off');
h1=uicontrol('style','edit','position',[80,165,160,30],'horizontal','right');
h2=uicontrol('position',[260,165,120,30],'string','查 询','fontsize',15','callback','word_find');
h3=uicontrol('style','listbox','position',[80,60,300,60],'horizontal','left','fontsize',10);
做个用于调用查询单词的m程序:
function word_find
[a,b,c,d,e]=dataread('file','text1.txt','%s%s%s%s%s');
str=get(findobj(gcf,'style','edit'),'string');
string=[];
for i=1:length(a)
if length(cell2mat(a(i)))==length(str)
if cell2mat(a(i))==str
string=strcat(str,'?',cell2mat(b(i)),'?',cell2mat(c(i)),'?',cell2mat(d(i)),'?',cell2mat(e(i)));
string(string=='?')=' '
set(findobj(gcf,'style','listbox'),'string',string);
end
end
end
if isempty(string)
set(findobj(gcf,'style','listbox'),'string','not find!');
end