Thread Subject: Saving data in a loop

Subject: Saving data in a loop

From: Simon Buckley

Date: 13 Nov, 2009 10:58:02

Message: 1 of 3

Hey guys,

I'm new to MATLAB and I am attempting to analyse data form FRFs and determine Outliers. I need to cycle through 15 sensors and 4097 spectral lines. How do I save the data as it cycles through? At the moment all I get is the last bit of Data

load N1.mat;
load D1.mat;
Total_mean=mean(FRFmagN1,3);

for sensor=1:1:15,
for start=1:10:4048,
sensor;
start;
Training_Feature=squeeze(FRFmagN1(sensor,start:start+49,:));
Testing_Feature=squeeze(FRFmagD1(sensor,start:start+49,:));
Feature_mean=Total_mean(sensor,start:start+49,:)';


Feature_Cov=cov(Training_Feature');
novelty=zeros(1,150);
for i=1:150;
    
novelty(1,i)=(Testing_Feature(:,i)-Feature_mean)'*inv(Feature_Cov)*(Testing_Feature(:,i)-Feature_mean);
end
end
end

I need to save each time it cycle through novelty(1,i)

Thanks

Subject: Saving data in a loop

From: Sebastiaan

Date: 13 Nov, 2009 13:25:03

Message: 2 of 3

"Simon Buckley" <Simonthomasbuckley@gmail.com> wrote in message <hdje3q$3a1$1@fred.mathworks.com>...
> Hey guys,
>
> I'm new to MATLAB and I am attempting to analyse data form FRFs and determine Outliers. I need to cycle through 15 sensors and 4097 spectral lines. How do I save the data as it cycles through? At the moment all I get is the last bit of Data

Well, you can either use a cell array, or save it to disk:

>
> load N1.mat;
> load D1.mat;
> Total_mean=mean(FRFmagN1,3);
>
novelty = cell(15, floor(4048/10)); % Make cell array

> for sensor=1:1:15,
> for start=1:10:4048,
> sensor;
> start;
> Training_Feature=squeeze(FRFmagN1(sensor,start:start+49,:));
> Testing_Feature=squeeze(FRFmagD1(sensor,start:start+49,:));
> Feature_mean=Total_mean(sensor,start:start+49,:)';
>
>
> Feature_Cov=cov(Training_Feature');

novelty{sensor, (start-1)/10+1}=zeros(1,150); % Initialize this cell with zeros

> for i=1:150;
>

% Write data
novelty{sensor, (start-1)/10+1}(1,i)=(Testing_Feature(:,i)-Feature_mean)'*inv(Feature_Cov)*(Testing_Feature(:,i)-Feature_mean);
> end
> end
> end
>
> I need to save each time it cycle through novelty(1,i)
>
> Thanks


Otherwise, after the first loop is finised:
save(sprintf('novelty_sensor_%02d_idx_%04d', time, start), novelty);

Sebastiaan

Subject: Saving data in a loop

From: Simon Buckley

Date: 13 Nov, 2009 13:52:03

Message: 3 of 3

"Sebastiaan " <s.breedveld@erasmusmc.REMOVE.BOO.BOO.nl> wrote in message <hdjmnf$rnf$1@fred.mathworks.com>...
> "Simon Buckley" <Simonthomasbuckley@gmail.com> wrote in message <hdje3q$3a1$1@fred.mathworks.com>...
> > Hey guys,
> >
> > I'm new to MATLAB and I am attempting to analyse data form FRFs and determine Outliers. I need to cycle through 15 sensors and 4097 spectral lines. How do I save the data as it cycles through? At the moment all I get is the last bit of Data
>
> Well, you can either use a cell array, or save it to disk:
>
> >
> > load N1.mat;
> > load D1.mat;
> > Total_mean=mean(FRFmagN1,3);
> >
> novelty = cell(15, floor(4048/10)); % Make cell array
>
> > for sensor=1:1:15,
> > for start=1:10:4048,
> > sensor;
> > start;
> > Training_Feature=squeeze(FRFmagN1(sensor,start:start+49,:));
> > Testing_Feature=squeeze(FRFmagD1(sensor,start:start+49,:));
> > Feature_mean=Total_mean(sensor,start:start+49,:)';
> >
> >
> > Feature_Cov=cov(Training_Feature');
>
> novelty{sensor, (start-1)/10+1}=zeros(1,150); % Initialize this cell with zeros
>
> > for i=1:150;
> >
>
> % Write data
> novelty{sensor, (start-1)/10+1}(1,i)=(Testing_Feature(:,i)-Feature_mean)'*inv(Feature_Cov)*(Testing_Feature(:,i)-Feature_mean);
> > end
> > end
> > end
> >
> > I need to save each time it cycle through novelty(1,i)
> >
> > Thanks
>
>
> Otherwise, after the first loop is finised:
> save(sprintf('novelty_sensor_%02d_idx_%04d', time, start), novelty);
>
> Sebastiaan

Thanks very much for that Sebastiaan!

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

Contact us at files@mathworks.com