MATLAB에 파일 이름과 파일 크기 만 표시하는 방법
-
21-12-2019 - |
문제
축을 사용하여 이미지를 소스 경로로 디스플레이 파일 이름으로 열려고 할 때.
- 파일 이름 : C : \ Users \ Win8 \ Documents \ MATLAB \ TEST \ LENA.PNG
- 파일 크기 : 606.09.
FileName (빨간색 테두리) 만 표시하고 소수점이없는 KB (파란색 테두리)에만 파일화를 표시하고 싶습니다.
- 파일 이름 : lena.png
- 파일 크기 : 606
axes1 콜백 코드 :
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);
.
어떤 조언을하는 방법 ??
나는 MATLAB R2012A를 사용하고 있습니다.
해결책
첫 번째 부분 : fileparts
:
[~, fn, ext] = fileparts(info.Filename); %// get filename (no path) and extension
set(project.edit1, 'String', [fn ext])
.
set(project.edit2, 'String', round(info.FileSize/1024))
.
또는 아마도 문자열에 단위 (KB)를 명시 적으로 표시 할 수도 있습니다.
set(project.edit2, 'String', [num2str(round(info.FileSize/1024)) ' kB'])
. 제휴하지 않습니다 StackOverflow