Como exibir apenas nome de arquivo e tamanho de arquivo no MATLAB
-
21-12-2019 - |
Pergunta
quando tento abrir uma imagem usando eixos como botão, seu nome de arquivo de exibição com caminho de origem.
- Nome do arquivo :C:\Users\Win8\Documents\MATLAB est\lena.png
- Tamanho do arquivo :606.09
eu só quero exibir apenas o nome do arquivo (borda vermelha) e o tamanho do arquivo em KB (borda azul) sem decimal.
- Nome do arquivo :lena.png
- Tamanho do arquivo :606
eixos1 Código de retorno de chamada:
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
project = guidata(gcbo);
[imgname, imgpath] = uigetfile({'*.png';}, 'Open an Image')
if imgname==0 % if it is canceled
imgname=''; % create an empty name
imgpath=''; % create an empty path
end
if isequal(imgname, 0)
return;
end
eval(['cd ''' imgpath ''';']);
I=imread(fullfile(imgpath, imgname));
set(project.figure1, 'CurrentAxes', project.axes1);
set(imshow(I));
imshow(I);
set(project.figure1, 'Userdata', I);
set(project.axes1, 'Userdata', I);
info = imfinfo(fullfile(imgpath, imgname));
set(project.edit1, 'String', info.Filename);
set(project.edit2, 'String', info.FileSize/1024);
alguma dica de como fazer??
estou usando o MATLAB R2012a.
Solução
Para a primeira parte:usar fileparts
:
[~, fn, ext] = fileparts(info.Filename); %// get filename (no path) and extension
set(project.edit1, 'String', [fn ext])
Para a segunda parte:usar round
:
set(project.edit2, 'String', round(info.FileSize/1024))
ou talvez indique explicitamente unidades (kB) na string:
set(project.edit2, 'String', [num2str(round(info.FileSize/1024)) ' kB'])
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow