Thread Subject: Loading unknown variables to workspace and performing calculations on them

Subject: Loading unknown variables to workspace and performing calculations on them

From: Becky J.

Date: 15 Sep, 2009 18:41:03

Message: 1 of 5

Hello,

I have an specified number of .mat files that may or may not exist, and I call them into my function by

for i = 2:week
    s = ['load Group' int2str(i) '.mat']
    eval(s);
end

I want to evaluate in all the GroupX.mat files in my folder, and than call them and compare them (they are nx4 matrices).

So I want to compare my previously saved Group2.mat to my current fGroup matrix I calculated.

I am having difficult explicitly pulling out my GroupX matrices to compare, I don't know how to reference them if I cannot assume they are Group2, Group3, ect...
Thanks,

Subject: Loading unknown variables to workspace and performing calculations on them

From: Becky J.

Date: 15 Sep, 2009 19:53:03

Message: 2 of 5

Correction, the loop looks like

for i = 2:week-1
    try
        s = ['load Group' int2str(i) '.mat'];
        eval(s);
    catch ME1
        idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
        sprintf('Could not find Week%d.mat',i);
    end

end

I would eventually like to place it a while loop that would do something like this

while t = 1
   load Groupx.mat
   compare fGroup and Groupx
break if different
   else rerun sorting function on fGroup and reset i
end


"Becky J." <rebecca.jaiven@gmail.com> wrote in message <h8on3v$pt5$1@fred.mathworks.com>...
> Hello,
>
> I have an specified number of .mat files that may or may not exist, and I call them into my function by
>
> for i = 2:week
> s = ['load Group' int2str(i) '.mat']
> eval(s);
> end
>
> I want to evaluate in all the GroupX.mat files in my folder, and than call them and compare them (they are nx4 matrices).
>
> So I want to compare my previously saved Group2.mat to my current fGroup matrix I calculated.
>
> I am having difficult explicitly pulling out my GroupX matrices to compare, I don't know how to reference them if I cannot assume they are Group2, Group3, ect...
> Thanks,

Subject: Loading unknown variables to workspace and performing calculations on them

From: Becky J.

Date: 15 Sep, 2009 19:54:02

Message: 3 of 5

Correction, the loop looks like

for i = 2:week-1
    try
        s = ['load Group' int2str(i) '.mat'];
        eval(s);
    catch ME1
        idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
        sprintf('Could not find Week%d.mat',i);
    end

end

I would eventually like to place it a while loop that would do something like this

while t = 1
   load Groupx.mat
   compare fGroup and Groupx
break if different
   else rerun sorting function on fGroup and reset i
end


"Becky J." <rebecca.jaiven@gmail.com> wrote in message <h8on3v$pt5$1@fred.mathworks.com>...
> Hello,
>
> I have an specified number of .mat files that may or may not exist, and I call them into my function by
>
> for i = 2:week
> s = ['load Group' int2str(i) '.mat']
> eval(s);
> end
>
> I want to evaluate in all the GroupX.mat files in my folder, and than call them and compare them (they are nx4 matrices).
>
> So I want to compare my previously saved Group2.mat to my current fGroup matrix I calculated.
>
> I am having difficult explicitly pulling out my GroupX matrices to compare, I don't know how to reference them if I cannot assume they are Group2, Group3, ect...
> Thanks,

Subject: Loading unknown variables to workspace and performing calculations on them

From: Becky J.

Date: 1 Oct, 2009 20:36:18

Message: 4 of 5

Hello,

Took a bit off, and now I'm back at the same problem. I'm pulling in an unknown quantity of data with unknown variables (they should be Groupx.mat files with an fGroup variable inside).

So I pull in my data...

files = dir('*.mat');

try
    for i = 1:numel(files)
        files(i).name
        load(files(i).name)
    end
    clear i
catch ME1
     idSegLast = regexp(ME1.identifier, '(?<=:)\w+$', 'match');
     sprintf('Could not find Week%d.mat',i);

end

Than I want to compare it to a constant (fGroup).

Any suggestions?
 Thanks!

Subject: Loading unknown variables to workspace and performing calculations on them

From: Becky J.

Date: 2 Oct, 2009 13:49:03

Message: 5 of 5

Quick fix...my loop now looks like

files = dir('*.mat');

for i = 1:numel(files)
        files(i).name
        foo = importdata(files(i).name)
end
  
Still not what I wanted to do, but its a step in the right direction :)

Tags for this Thread

Everyone's Tags:

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.

Tag Activity for This Thread
Tag Applied By Date/Time
comparison Becky J. 15 Sep, 2009 15:54:14
eval Becky J. 15 Sep, 2009 14:59:48
load Becky J. 15 Sep, 2009 14:59:47
rssFeed for this Thread

Contact us at files@mathworks.com