error while evaluating uicontrol call back
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
function main_OpeningFcn(hObject, ~, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_OutputFcn(~, ~, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, ~, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global fname;
FileName = imread('1.jpg');
img=imread(FileName);
axes(handles.axes1);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
img=imread(strcat('D/',fname));
axes(handles.axes2);
imshow(img);
fname=FileName;
handles.filename=FileName;
guidata(hObject,handles)
2 commentaires
Réponse acceptée
Geoff Hayes
le 7 Mar 2019
vidhya - your pushbutton1 callback has the following two lines of code
FileName = imread('1.jpg');
img=imread(FileName);
One problem may be that MATLAB cannot find the 1.jpg file (you may want to provide the full path to this file). Even if this does work what is actually happening with
FileName = imread('1.jpg');
You are attempting to read an image file named 1.jpg and are storing the result into a variable that is incorrectly FileName. This isn't a file name but an image! And so then on the next line of code
img=imread(FileName);
you are passing a matrix (image) into the imread function.This could be the source of the error. These two lines should just be reduced to
img = imread('1.jpg'); % better yet - provide the full path to the file
Also, remove the global variable. You don't need this especially as you are already using the handles structure to store FileName (or perhaps you want to store the image?).
This line
img=imread(strcat('D/',fname));
2 commentaires
Geoff Hayes
le 7 Mar 2019
that's a lot of code...
In your pushbutton1 callback, why are you still doing
FileName = imread('1.jpg');
img=imread('1.jpg');
FileName is an inappropriately named variable for the image. Why read the image twice? For what purpose? And then you assign this to the global variable fname. Why do this? This isn't a file name. And you have the handles structure that you are already assigning this image too. Don't duplicate and don't use global variables.
Now in your pushbutton2 callback, you do
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(~, ~, ~)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
warning off;
global fname;
%% Procedure for RHS
fid=fopen('fname.txt','w');
fprintf(fid,'%s',fname);
fclose(fid);
test
Look what you are writing to file:
fprintf(fid,'%s',fname);
fname is an image (matrix)...it isn't a string. So that is probably the source of the error. There is also a call to test. What is this? That will throw an error too...
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Point Cloud Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!