From: Chris Rock on
Hi,

I'm very new to MATLAB, so forgive me if this is a bit of a simple question.

I've imported an Excel spreadsheet of data into MATLAB, creating separate variables for each column/parameter. I'm now wanting to extract data that's greater than 0 from one of the columns and read it into the corresponding location in a new variable, and return 0 for all the other locations where the source data is 0 or less than 0.

I've tried an 'if' statement:

if EBatt(:,:)>0;
EBI(:,:) = EBatt(:,:);
end

but this doesn't work. EBatt is the source data and EBI is the new variable I've created. Can anyone help me, please?

Many thanks,

Chris
From: Andy on
"Chris Rock" <chris.rock(a)cenex.co.uk> wrote in message <i3efco$ge3$1(a)fred.mathworks.com>...
> Hi,
>
> I'm very new to MATLAB, so forgive me if this is a bit of a simple question.
>
> I've imported an Excel spreadsheet of data into MATLAB, creating separate variables for each column/parameter. I'm now wanting to extract data that's greater than 0 from one of the columns and read it into the corresponding location in a new variable, and return 0 for all the other locations where the source data is 0 or less than 0.
>
> I've tried an 'if' statement:
>
> if EBatt(:,:)>0;
> EBI(:,:) = EBatt(:,:);
> end
>
> but this doesn't work. EBatt is the source data and EBI is the new variable I've created. Can anyone help me, please?
>
> Many thanks,
>
> Chris

EBI = EBatt; % copy the data
EBI(EBI<0) = 0; % set all negative data to 0.
From: Chris Rock on
"Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i3ego0$f0d$1(a)fred.mathworks.com>...
> "Chris Rock" <chris.rock(a)cenex.co.uk> wrote in message <i3efco$ge3$1(a)fred.mathworks.com>...
> > Hi,
> >
> > I'm very new to MATLAB, so forgive me if this is a bit of a simple question.
> >
> > I've imported an Excel spreadsheet of data into MATLAB, creating separate variables for each column/parameter. I'm now wanting to extract data that's greater than 0 from one of the columns and read it into the corresponding location in a new variable, and return 0 for all the other locations where the source data is 0 or less than 0.
> >
> > I've tried an 'if' statement:
> >
> > if EBatt(:,:)>0;
> > EBI(:,:) = EBatt(:,:);
> > end
> >
> > but this doesn't work. EBatt is the source data and EBI is the new variable I've created. Can anyone help me, please?
> >
> > Many thanks,
> >
> > Chris
>
> EBI = EBatt; % copy the data
> EBI(EBI<0) = 0; % set all negative data to 0.


Brilliant! Thanks Andy.