MATLAB: I have a problem. Help me please! I want to show a size of a picture

show size

% --- Executes on button press in size.
function size_Callback(hObject, eventdata, handles)
% hObject handle to size (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

info = imfinfo(image);
s=strcat(info.Width,info.Height);
set(handles.text2,'string',num2str(s));
guidata(hObject, handles);
% --- Executes on button press in open.
function open_Callback(hObject, eventdata, handles)
% hObject handle to open (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, path1 ]= uigetfile('*.*', 'MultiSelect', 'on');
image = imread(filename);
p=strcat(path1,filename);
axes(handles.axes1);
imshow(image);
guidata(hObject, handles);
set(handles.path,'string',p);
set(handles.text4,'string',filename);

Best Answer

I guess you're not seeing the image info that you want because you of this line:
s=strcat(info.Width,info.Height);
The data returned by info.Height and info.Width of type 'double', so what happens is that you are concatenating non-string data, hence strcat converts each entry to a char, such that the command effectively responds as if you wrote:
s = strcat(char(info.Width),char(info.Height));
which is of course not what you wanted to do.
What you should do is to first convert each number to a string. So the following change should work:
s = sprintf('width = %d, height = %d',info.Width,info.Height); % output is: width = 30, height = 0 if inputs are 30 and 40.
OR
s = strcat(num2str(info.Width),num2str(info.Height)); % output is: 3040 if inputs are 30 and 40.
Related Question