Domanda

Quando provo ad aprire un'immagine usando gli assi come pulsante del file del suo display con il percorso di origine.

    .
  • Nome file: c: \ Users \ win8 \ Documents \ matlab \ Test \ Lena.png
  • Dimensione del file: 606.09
    Inserisci l'immagine Descrizione qui

Voglio solo visualizzare il nome file (bordo rosso) solo e files size in KB (Blue Border) senza decimale.

    .
  • Nome file: Lena.png
  • Dimensione del file: 606

AXES1 CODICE CALLBACK:

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

Qualche consiglio Come farlo ??
Sto usando MATLAB R2012A.

È stato utile?

Soluzione

Per la prima parte: utilizzare fileparts :

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

per la seconda parte: utilizzare round :

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

o forse indicano esplicitamente le unità (KB) nella stringa:

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

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top