Thread Subject: gui/excel/array

Subject: gui/excel/array

From: helena raz

Date: 5 Feb, 2008 23:58:01

Message: 1 of 3

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'
            dname = [dname, '\'] ;
        else
        end
    end
        handles.metricdata.dname = dname;
        guidata(hObject,handles)
        directory = handles.metricdata.dname;
        [FileName,PathName,FilterIndex] =
uigetfile('*.xls','select the excel file');
        filename = strcat(FileName)
        importmatrix = importdata(filename);
    
eval([filename,'=directory;'])
xx = xlsread(filename)


handles.metricdata.dname = dname;
directory = handles.metricdata.dname


handles.metricdata.xx = xx;
xx = handles.metricdata.xx;
 

Subject: gui/excel/array

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 6 Feb, 2008 00:22:29

Message: 2 of 3

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

Subject: gui/excel/array

From: helena raz

Date: 6 Feb, 2008 15:43:02

Message: 3 of 3

the beginning stuff doesn't really matter.

what I want is put that info into an array. yes it is done by :
xx = xlsread(filename)

and then saved by:

handles.metricdata.xx = xx;

so that can use it elsewhere (i.e. other function callbacks).


the problem is when I do so, i get an error that xx does not
exist.

do you know why?

thanks.

Tags for this Thread

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com