Pregunta

Cuando intento abrir una imagen usando ejes como botón, su nombre de archivo de pantalla con ruta de origen.

  • Nombre del archivo: C: \ Usuarios \ Win8 \ Documents \ Matlab \ Test \ Lena.png
  • Tamaño del archivo: 606.09
    ingrese la descripción de la imagen aquí

Solo quiero mostrar el nombre de archivo (borde rojo) y solo con archivos en KB (borde azul) sin decimal.

  • Nombre de archivo: lena.png
  • Tamaño del archivo: 606

AXES1 Código de devolución de llamada:

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);

¿Algún consejo cómo hacerlo? Estoy usando MATLAB R2012A.

¿Fue útil?

Solución

Para la primera parte: use fileparts :

[~, fn, ext] = fileparts(info.Filename); %// get filename (no path) and extension
set(project.edit1, 'String', [fn ext])

Para la segunda parte: use round :

set(project.edit2, 'String', round(info.FileSize/1024))

o tal vez indican explícitamente unidades (KB) en la cadena:

set(project.edit2, 'String', [num2str(round(info.FileSize/1024)) ' kB'])

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top