|
In article <foat69$raq$1@fred.mathworks.com>,
helena raz <helena.raz@gmail.com> wrote:
>Im making a gui using guide that has a browse pushbutton to
>select an excel file. the goal is to put that into an array
>which is then accessible to other function callbacks. im not
>sure how to do this.
>format short e;
>str = get(hObject,'String');
>val = get(hObject,'Value');
>
>if isempty(val)
> val = 'file is empty'
>else
> dname = uigetdir;
> if dname ~= 0
> if dname(end) ~= 'FILESEP'
filesep is a function that returns the appropriate file seperator.
You are comparing dname(end) to the literal string 'FILESEP'
which will produce a vector result and the 'if' will be true
only if all members of the vector are true... which will never be
the case because no character can equal 'F' and 'I' simultaneously.
> dname = [dname, '\'] ;
As you are already coding FILESEP, you should concatenate on FILESEP
instead of '\'.
> else
> end
> end
> handles.metricdata.dname = dname;
> guidata(hObject,handles)
> directory = handles.metricdata.dname;
> [FileName,PathName,FilterIndex] =
>uigetfile('*.xls','select the excel file');
If you know the directory already, why are you not providing it to
uigetfile ?
> filename = strcat(FileName)
strcat passed a single argument would return the argument without
change. I suspect you mean strcat(PathName, FileName)
the effect of which you could get more portably with the function
fullfile(). On the other hand, having a seperator in the name
would conflict with your eval() below.
> importmatrix = importdata(filename);
>eval([filename,'=directory;'])
I do not understand what you are trying to do there. In that
statement, you are taking the filename and asking to create
a variable whose name is the filename and whose content is the
directory name you extracted from the handle. But suppose the
user selected out of a different directory? The PathName output
from uigetfile() tells you the directory actually selected from.
Based upon the '\' file seperator in your earlier code, we can
deduce that you are using Windows rather than Unix. In that case,
nearly all file names that you get from the system will include
a period and an extension, such as 'testdata.xls'. Because you
put the value of the filename into the eval() statement, that would
look something like eval('testdata.xls=directory;'). You can
see the problem -- that would set a structure field... if it
turned out that the base filename happened to be a valid matlab
identifier, which is not certain for a user filename picked from
a directory.
>xx = xlsread(filename)
>handles.metricdata.dname = dname;
>directory = handles.metricdata.dname
>handles.metricdata.xx = xx;
>xx = handles.metricdata.xx;
That last line looks redundant. You take the result of the read,
store it in a variable, store that variable in another variable,
then store that variable back in the first variable.
>select an excel file. the goal is to put that into an array
>which is then accessible to other function callbacks.
To put the filename into the array, or to put the data into
the array? If it is the data, then your handles.metricdata.xx = xx;
statement should do the work. Just remember to use guidata(handles);
when you are through so that the handles get updated for use
with other routines.
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
|