generic filenames for .mat files taken from excel document

  • Follow


Hi!

I have an excel file, where different filenames are written in the first column. 
Ex. files.xls
   A     B ......
1 File1
2 File2
  .
  .
  .

Only the file names are included in the excel document. All the file names in the excel document have a correpsonding .mat file, with the same file name. The .mat files looks like this:

fileX=

    X1    X2     X3    X4    X5

X1, X2...are different numerical values. I want to be able to loop through the filenames in the excel document and then use the filename no loop through the values in the corresponding . mat file. I do not manage to keep the connection between the filename and the .mat file when i try to make it generic. 

I have tried :

[values, text, allData] = xlsread('test.xls');
fileName = cell2mat(allData(1,1)); % to get the file name
value = fileName(1,1); %to get the first value in fileX.mat

then value = f, since it is the first letter in the filename. This isn't exactly what I am looking for. 

What i want is that value should be the first value in fileX, thus X1.

Do any one have a solution for this problem? I would really much appreciate it!
0
Reply Rebecka 11/10/2010 11:42:03 AM

You need to pass filename into the load() function.
0
Reply ImageAnalyst 11/10/2010 11:50:14 AM


How do you mean? All the .mat-files are already loaded and they are in the workspace. 

Is there something else I have to do?

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <f17d9e25-6616-4c75-8a89-0df02784782a@s4g2000yql.googlegroups.com>...
> You need to pass filename into the load() function.
0
Reply Rebecka 11/10/2010 11:57:04 AM

You say
    value = fileName(1,1); %to get the first value in fileX.mat
well, fileName is a string - a character variable, right?  It's, for
example 'X1.mat' so fileName(1,1) will give 'X' and fileName(1,2) will
give '1' - understand?

You say that the mat files are already loaded and are in the
workspace.  The way to do this is with the load() command/function.
Did you use the load function?  You didn't show it in your code.
Apparently you incorrectly thought that
    value = fileName(1,1)
would be the same as
    value = load(fileName)
but it's not.  The first one gets a character from the string and the
second one loads the mat file.
0
Reply ImageAnalyst 11/10/2010 2:23:03 PM

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <6a580871-5a91-43ce-8594-b61fa8aacb13@k11g2000vbf.googlegroups.com>...
> You say
>     value = fileName(1,1); %to get the first value in fileX.mat
> well, fileName is a string - a character variable, right?  It's, for
> example 'X1.mat' so fileName(1,1) will give 'X' and fileName(1,2) will
> give '1' - understand?
> 
> You say that the mat files are already loaded and are in the
> workspace.  The way to do this is with the load() command/function.
> Did you use the load function?  You didn't show it in your code.
> Apparently you incorrectly thought that
>     value = fileName(1,1)
> would be the same as
>     value = load(fileName)
> but it's not.  The first one gets a character from the string and the
> second one loads the mat file.

All the .mat-files were saved using 
save all_mat_files
and then in my code i put
load all_mat_files to have the files in the workspace...
The problem I had was to connect to these files in a generic way. 
Now I´ve found a solution!

instead of:
fileName = cell2mat(allData(1,1)); % to get the file name
value = fileName(1,1); %to get the first value in fileX.mat

I used
fileName= cell2mat(allData(1,1));
value = eval([fileNamel '(1,1)']); 

this works great.

Thanks for the help anyway and I am sorry that I wasn't clear enough in my question!
0
Reply Rebecka 11/12/2010 7:58:04 AM

On Nov 12, 2:58=A0am, "Rebecka " <villi...@student.chalmers.se> wrote:
[snip]
> this works great.
>
> Thanks for the help anyway and I am sorry that I wasn't clear enough in m=
y question!
---------------------------------------------------------------------------=
--------------

I'm a little bit surprised that you chose not to use the method I (and
virtually everyone else) recommends, and chose to use instead a method
that even the Mathworks recommends you NOT use.  But whatever - it's
your code.  Good luck with it.

http://matlab.wikia.com/wiki/FAQ#Why_is_it_advised_to_avoid_using_the_.22ev=
al.22_function.3F
http://www.mathworks.com/support/tech-notes/1100/1103.html

0
Reply ImageAnalyst 11/12/2010 1:00:45 PM

5 Replies
210 Views

(page loaded in 0.07 seconds)

Similiar Articles:













7/22/2012 4:40:38 AM


Reply: