matlab run script file from GUI push button - matlab

i have a script file , want to run it from gui push button
its not working .
the error is :
Undefined variable "classifyDeeb" or class "classifyDeeb.m".
Error in Train>pushbutton2_Callback (line 113)
classifyDeeb.m
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in Train (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)Train('pushbutton2_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
------------------
scrip file code `load deeb;
trdata=[deeb(1:8,2:6);deeb(11:18,2:6)];
gr=[deeb(1:8,1);deeb(11:18,1)];
testdata=[deeb(9:10,2:6);deeb(19:20,2:6)];
svmstr=svmtrain(trdata,gr);
result = svmclassify(svmstr,testdata);
output = result;`
----------------------------
the pushbutton2_Callback code is :
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
classifyDeeb.m
the script file, the figure and the matrix data ( deeb.mat) file are in the same folder.
please help
thanks in advance for help

Two options:
You can use run() on the m-file name. You can even include the full path to the script if it is in another directory.
function pushbutton2_Callback(hObject, eventdata, handles)
run('classifyDeeb.m')
or call it without the extension. This will work as long as it is located in on of the Matlab's Paths.
function pushbutton2_Callback(hObject, eventdata, handles)
classifyDeeb

Related

Error in loading variables from GUI to workspace in Matlab

I have created a GUI in Matlab and made a simple pushbutton function in GUI for running my matlab file.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Uncertainty_MMS_refactored_Final;
I can load my text files (e.g. PTX_Data_Raw.txt) via GUI in workspace by using assignin function.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
[filename_2,PathName]=uigetfile({'*.txt'},'Import Reference PTX file without header');
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
PTX_Raw = importdata(filename_2);
assignin('base', 'PTX_Data_Raw', PTX_Raw);
content = filename_2;
set(handles.edit2, 'string', content,'fontsize',12);
But when I run my code via GUI byy pusshing "push button" button I receive this error:
Undefined function or variable 'PTX_Data_Raw'
while I check my workspace, I can see all files that I have loaded from GUI to workspace and even I can run my program with F5 button via keyboard! but I don't know why I can run my code via GUI?! HERE is the code that I have written for running my matlab file. here is the full error that I receive:
Undefined function or variable 'PTX_file'.
Error in Uncertainty_MMS_refactored_Final (line 21)
RefOrgnizedData = OrgnizingData(PTX_file, PTX_Data_Raw);
Undefined function or variable 'PTX_file'.
Error in GUI>pushbutton7_Callback (line 178)
Uncertainty_MMS_refactored_Final;
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in GUI (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)GUI('pushbutton7_Callback',hObject,eventdata,guidata(hObject))
Error using waitfor
Error while evaluating UIControl Callback
Should I change or add something else more? please help me

MATLAB GUI Error while using set

why I cant have the output in the edit text?
% --- Executes on button press in f.
function f_Callback(hObject, eventdata, handles)
% hObject handle to f (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
clc
syms t
a=str2double(get(handles.b1,'string'));
b=str2double(get(handles.c1,'string'));
y=eval(get(handles.a1,'string'));
u=a-b;
m=abs(y).^2;
r=int(m,t);
g1=subs(r,t,a);
h=subs(r,t,b);
fh=g1-h;
s=fh./u
set(handles.e,'string',s)';
Command window shows the answer not edit text.The error is:
Error using set
error: mxArray must be double, char, or cell
Error in signalproject2>f_Callback (line 284)
set(handles.e,'string',s)';
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in signalproject2 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)signalproject2('f_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Can u please help me with this?
What is the data type of s? Use whos s to find out.
If it's not a double, char, or cell then you won't be able to assign it as a string for your edit box. This is exactly what the error message tells you.
I don't have the symbolic math toolbox so I can't check the code, but I'm guessing s is a symbolic array. If this is the case, see the documentation for char to convert the symbolic array to a string so you can assign it properly.
Could it simply be because there is a ' you don't want at the end of this line:
set(handles.e,'string',s)';
what if you try:
set(handles.e,'string',s);

MATLAB, GUIDE, viewing the slice number on a dicom stack

I want to view the number of the slice that I'm examining via a simple previous/next slice GUI. I store number of the slice that I'm viewing on handles.index and I'm able to update it via the previous, next pushbuttons.
I wrote the following on the edit text callback function:
function edit2_Callback(hObject, eventdata, handles)
handles.output=hObject
set (edit2.handles,'Tag', handles.index); %also tried with the 'String' property and failed
The Property is not updating when the code is running. It remains as 'Edit Text', what's wrong here?
Full Code, Dicom file
Duh, I made the update on the pushbutton callbacks, and it works fine :)
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
handles.output = hObject;
handles.index = handles.index+1;
Cek (hObject, eventdata, handles);
imshow(handles.image_data(:,:,handles.index),'DisplayRange',[]);
set (handles.edit2,'String', handles.index);

MATLAB GUI calculator error

I'm Developing a calculator that converts back and forth from a Julian time to a standard IRIG time using MATLAB's GUIDE. When started, the calculator works fine going one way, or starting out going the other way, but somehow something gets deleted when going back and forth in the same session. I'm only using two buttons, and this is what the code looks like for the callbacks of those two buttons:
% --- Executes on button press in convertjulian.
function convertjulian_Callback(hObject, eventdata, handles)
% hObject handle to convertjulian (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
value = handles.isec;
day = floor(value/86400);
remainder = (value/86400 - day)*86400;
hour = floor(remainder/3600);
remainder = (remainder/3600 - hour)*3600;
min = floor(remainder/60);
sec = (remainder/60 - min)*60;
set(handles.jday,'String',day);
set(handles.jhour,'String',hour);
set(handles.jmin,'String',min);
set(handles.jsec,'String',sec);
Here is the other callback:
% --- Executes on button press in convertirig.
function convertirig_Callback(hObject, eventdata, handles)
% hObject handle to convertirig (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
seconds=handles.jday*86400+handles.jhour*3600+handles.jmin*60+handles.jsec;
set(handles.isec,'String',sprintf('%0.3f',seconds));
And here is the error that I get in MATLAB when I'm running it:
Error using handle.handle/set
Invalid or deleted object.
Error in timeconversion>convertjulian_Callback (line 124)
set(handles.jday,'String',day);
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in timeconversion (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in #(hObject,eventdata)timeconversion('convertjulian_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
You are treating handles as numeric values. To get the value from a handles.isec, you can use:
value = str2double(get(handles.isec, 'String'));
All the 'j' handles will be similar.

Getting snapshot from webcam in Matlab

I have created a simple GUI to preview webcam stream and to get snapshot from it. For this I have created on axes to show video, one push button(pushbutton1) to start preview, one push button(pushbutton2) to get snapshot. Following is the code for these two push buttons.
function pushbutton1_Callback(hObject, eventdata, 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)
axes(handles.axes1);
vidObj = videoinput('winvideo',1);
videoRes = get(vidObj, 'VideoResolution');
numberOfBands = get(vidObj, 'NumberOfBands');
handleToImage = image( zeros([videoRes(2), videoRes(1), numberOfBands], 'uint8') );
preview(vidObj, handleToImage);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% 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)
a=getsnapshot(get(axes,'Children'));
imshow(a);
In pushbutton2_Callback I am trying to get child of axes ie. vidObj. But this gives me error ??? Undefined function or method 'getsnapshot' for input arguments of type 'double'.. Why is it returing double type instead of child object vidObj?
How can I fix it and get snapshot?
Is there any other better way?
(I just started learning GUI.)
Thanks.
A better alternative to declaring your variables global, is to use the handles structure for sharing data. GUIDE already uses this structure to store handles to all GUI components. Simply add your data as a field to this structure that gets passed around to all callback functions.
So inside the first callback:
function pushbutton1_Callback(hObject, eventdata, handles)
%# ... your existing code ...
%# store video object in handles, and persist
handles.vidObj = vidObj;
guidata(hObject,handles)
end
Then in the second, you can retrieve the video object from the handles structure:
function pushbutton2_Callback(hObject, eventdata, handles)
frame = getsnapshot(handles.vidObj);
imshow(frame);
end