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
| function test
figure;
uicontrol('style', 'pushbutton', ...
'units', 'normalized', ...
'position', [0.05 0.4 0.2 0.1], ...
'string', 'Get a File...', ...
'callback', @getAndShowFile);
uicontrol('style', 'pushbutton', ...
'units', 'normalized', ...
'position', [0.05 0.2 0.2 0.1], ...
'string', 'Clear', ...
'callback', @clearText);
uicontrol('style', 'text', ...
'units', 'normalized', ...
'position', [0.3 0.1 0.6 0.8], ...
'tag', 'txt');
function getAndShowFile(obj, event)
[filename, pathname] = uigetfile('*.txt', 'Get a File');
if ~filename
return
end
fid = fopen(fullfile(pathname, filename), 'r');
if fid==-1
err = sprintf('Unable to open file %s', fullfile(pathname, filename));
errordlg(err)
end
X = textscan(fid, '%s', 'delimiter', '\n');
fclose(fid);
h = findobj('style', 'text', 'tag', 'txt');
set(h, 'string', X{1});
function clearText(obj, event)
h = findobj('style', 'text', 'tag', 'txt');
set(h, 'string', []); |
Partager