From: Kevin on
Hello All,

I have been having trouble with this GUI i am creating for a program to track a external data. When I input the necessary data and start my run, I am met with the following error, stating that it cannot create my file:
??? Error using ==> fopen
Invalid filename.

Error in ==> blpqui>pushbutton1_Callback at 171
new_file=fopen(opfname,'w');

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> blpqui at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)blpqui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))

??? Error while evaluating uicontrol Callback

I am not sure as to what the problem is, as I have used the original code to run without the GUI and it worked fine, any ideas? I have attached the code below, where handles.user_entry and handles.numH and handles.user_entry are editable inputs from the GUI. Thanks in advance!

% Start Run
function pushbutton1_Callback(hObject, eventdata, handles)

if (instrfind ~= 0)
fclose(instrfind);
end

clc

numS=handles.numH*3600; %Seconds to run
delay=2; %Interval delay in seconds

PS = gpib('agilent',7,6);
DAQ = gpib('agilent',7,9);
fopen(PS) %open the power supply
fopen(DAQ) % open the data acquisition box
fprintf(DAQ,'ABOR'); % stop any ongoing scans in the data acquisition box
fprintf(DAQ, '*IDN?');
disp([fscanf(DAQ) ' connected.']);

fprintf(DAQ,'CONF:TEMP FRTD,85,(@103)'); %Set to FRTD four wire
fprintf(DAQ,'CONF:TEMP FRTD,85,(@104)'); %Set to FRTD four wire
fprintf(DAQ,'CONF:FREQ AUTO,(@107)'); %Set channel 107 for freq meas
fprintf(DAQ,'STAT:OPER:ENAB'); %Standard operations register enabled
fprintf(DAQ,'SENS:CURR:AC:BAND 3,(@107)'); %Set to low freq (faster data aquisition)
NumPoints=10; % total amount of data points you want

opfname=[date '_' handles.user_entry '.csv']
new_file=fopen(opfname,'w');
fprintf(new_file,[['Time (S) | Started: ',datestr(now)] ',T1,T2,Delta T,Cell Temp,Pressure,Flow Meter freq ,Voltage,Current,Pin,Time 2(S),Tamb,Pout,\n']);
From: Walter Roberson on
Kevin wrote:

> % Start Run
> function pushbutton1_Callback(hObject, eventdata, handles)
>
> if (instrfind ~= 0)
> fclose(instrfind);
> end

Unless this function is a nested function of a function that defines
instrfind, instrfind is going to be undefined when the callback is involved,
whcih would lead to the error you see. Even if it is a nested funtion, you
would have to define instrfind before the callback was invoked, which could
mean initializing the button with 'Enable', 'off' until instrfind is well defined.

I do not see anything in the code that you presents that defines instrfind,
and since your routine does not end with an 'end' statement that matches the
'function' statement, your function pushbutton1_Callback cannot possibly be a
nested function (all nested functions must have an 'end' matching the
'function' line.)
From: Steven Lord on

"Walter Roberson" <roberson(a)hushmail.com> wrote in message
news:hqsqvc$4rv$1(a)canopus.cc.umanitoba.ca...
> Kevin wrote:
>
>> % Start Run
>> function pushbutton1_Callback(hObject, eventdata, handles)
>>
>> if (instrfind ~= 0)
>> fclose(instrfind);
>> end
>
> Unless this function is a nested function of a function that defines
> instrfind, instrfind is going to be undefined when the callback is
> involved, whcih would lead to the error you see. Even if it is a nested
> funtion, you would have to define instrfind before the callback was
> invoked, which could mean initializing the button with 'Enable', 'off'
> until instrfind is well defined.

Or the OP could be calling the INSTRFIND function to locate serial port
objects, which he then closes using FCLOSE if any are open.

http://www.mathworks.com/access/helpdesk/help/techdoc/ref/instrfind.html

Walter, weren't you discussing the calling of functions with 0 inputs
without using parentheses just recently in another thread? :)

Kevin, looking at the original error, you should probably display the file
name just before you try to FOPEN it to make sure it contains what you think
it should contain. If that doesn't show anything out of the ordinary, call
FOPEN with 2 outputs and see what the message contained in the second output
says.

--
Steve Lord
slord(a)mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ


From: Kevin on
"Steven Lord" <slord(a)mathworks.com> wrote in message <hqsrvo$enu$1(a)fred.mathworks.com>...
>
> "Walter Roberson" <roberson(a)hushmail.com> wrote in message
> news:hqsqvc$4rv$1(a)canopus.cc.umanitoba.ca...
> > Kevin wrote:
> >
> >> % Start Run
> >> function pushbutton1_Callback(hObject, eventdata, handles)
> >>
> >> if (instrfind ~= 0)
> >> fclose(instrfind);
> >> end
> >
> > Unless this function is a nested function of a function that defines
> > instrfind, instrfind is going to be undefined when the callback is
> > involved, whcih would lead to the error you see. Even if it is a nested
> > funtion, you would have to define instrfind before the callback was
> > invoked, which could mean initializing the button with 'Enable', 'off'
> > until instrfind is well defined.
>
> Or the OP could be calling the INSTRFIND function to locate serial port
> objects, which he then closes using FCLOSE if any are open.
>
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/instrfind.html
>
> Walter, weren't you discussing the calling of functions with 0 inputs
> without using parentheses just recently in another thread? :)
>
> Kevin, looking at the original error, you should probably display the file
> name just before you try to FOPEN it to make sure it contains what you think
> it should contain. If that doesn't show anything out of the ordinary, call
> FOPEN with 2 outputs and see what the message contained in the second output
> says.
>
> --
> Steve Lord
> slord(a)mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Hi Steven,

Thank you for clarifying the instrfind command for me, it saved me writing an extra post :)

When I ran the GUI this time, I gave it the parameter 'test' for handles.user_entry, and when I try to run the full GUI, it gives me the following:

HEWLETT-PACKARD,34970A,0,8-1-2
connected.

opfname =

'23-Apr-2010' '_' 'test' '.csv'

??? Error using ==> fopen
Invalid filename.

Error in ==> blpqui>pushbutton1_Callback at 171
new_file=fopen(opfname,'w');

Error in ==> gui_mainfcn at 96
feval(varargin{:});

Error in ==> blpqui at 42
gui_mainfcn(gui_State, varargin{:});

Error in ==> @(hObject,eventdata)blpqui('pushbutton1_Callback',hObject,eventdata,guidata(hObject))


??? Error while evaluating uicontrol Callback


I am not sure why, but I did realize that rather than creating opfname as 23-Apr-2010_test.csv, it outputs opfname as '23-Apr-2010' '_' 'test' '.csv'. Why would it not concatenate the parts in a GUI like it normally does in a regular m file?
From: Walter Roberson on
Steven Lord wrote:

> Or the OP could be calling the INSTRFIND function to locate serial port
> objects, which he then closes using FCLOSE if any are open.

Can't be. instrfind as a function is defined as returning a vector of handles,
and an empty array if no objects were found. The OP in the next line of code had

if (instrfind ~= 0)

which would correspond to

if all(instrfind ~= 0)

If 0 is a possible handle returned by instrfind then the all() can return
false even though non-zero handles might be also be returned. As, though,
handle 0 is reserved for standard input it cannot be returned by instrfind,
which at first glance makes the test redundant. However, if instrfind returns
[] then the test becomes "if all([] ~= 0)" which simplifies to "if all([])"
which is true, which would cause the fclose to be executed even though there
sis nothing to close. As we must assume that the user's code is correct and
rational, we must conclude that the user somehow has a different instrfind in
scope.


> Walter, weren't you discussing the calling of functions with 0 inputs
> without using parentheses just recently in another thread? :)

Ummm, maybe. Not saying I did, and not saying I didn't, but if I _did_, the
reason why would have been,

"A tall and good and not excessively rich and bald and very smart and good
tall and tall and terrified and rich and not very terrified and smart and tall
and young hamster insisted on it."