1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| function main
fig=figure;
uicontrol(fig, ...
'Style', 'pushbutton', ...
'String', 'Save...', ...
'Units','normalized','Position', [0.1 0.75 0.08 0.07], ...
'Callback', @save_text);
uicontrol(fig, ...
'Style', 'pushbutton', ...
'String', 'Read...', ...
'Units','normalized','Position', [0.3 0.75 0.08 0.07], ...
'Callback', @read_text);
text=uicontrol(fig,'style','edit','units','normalized',...
'String','Votre phrase ...','position',[0.2 0.2 0.5 0.5]);
function save_text(src,evt)
text2=get(text,'String');
formatOut = 'HH_MM_SS_dd_mmm_yyyy';
temp=datestr(now,formatOut);
choice =questdlg('Souhaitez vous enregistrer le texte ?','Save','Oui','Non','Non');
switch choice
case 'Oui'
[FileName,PathName] = uiputfile('*.txt','Enregistrement du texte',['Texte_',temp]);
if isequal(FileName,0) || isequal(PathName,0)
disp('Texte non enregistré');
else
fid=fopen(fullfile(PathName,FileName),'w');
fprintf(fid,'%s',text2.');
fclose(fid);
disp(['Texte dans un le fichier : ',FileName]);
end
case 'Non'
disp('Texte non enregistré');
end
end
function read_text(src,evt)
choice =questdlg('Souhaitez vous lire le texte ?','Save','Oui','Non','Non');
switch choice
case 'Oui'
[FileName,PathName] = uigetfile('*.txt','Lecture du fichier');
if isequal(FileName,0) || isequal(PathName,0)
disp('Fichier non lu');
else
fid=fopen(fullfile(PathName,FileName),'rt');
texte = fscanf(fid, '%s');
fclose(fid);
set(text,'String',texte)
end
case 'Non'
disp('Fichier non lu');
end
end
end |
Partager