From: antonio ferreira on
Hi all,

I am trying to do an average of all lines of a matrix (vel_u_filt)[600*103]. In some positions of the matrix I have NaN values. At the end I would like to have a [600*1] matrix. For this purpose I have written the following part of a code that it`s not working correctly. Can anyone give me a hint in order to do what I pretend. Regards

sum=0;
cont=0;
for i=1:size(vel_u_filt,1)
for j=1:size(vel_u_filt,2)
if isnan(vel_u_filt)== 0
sum(i)=sum+vel_u_filt;
cont(i)=cont+1;
end
end
end

vel_u_DA=sum(i)/cont(i);
From: us on
"antonio ferreira" <edgar.acferreira(a)gmail.com> wrote in message <i1ple3$qrr$1(a)fred.mathworks.com>...
> Hi all,
>
> I am trying to do an average of all lines of a matrix (vel_u_filt)[600*103]. In some positions of the matrix I have NaN values. At the end I would like to have a [600*1] matrix. For this purpose I have written the following part of a code that it`s not working correctly. Can anyone give me a hint in order to do what I pretend. Regards
>
> sum=0;
> cont=0;
> for i=1:size(vel_u_filt,1)
> for j=1:size(vel_u_filt,2)
> if isnan(vel_u_filt)== 0
> sum(i)=sum+vel_u_filt;
> cont(i)=cont+1;
> end
> end
> end
>
> vel_u_DA=sum(i)/cont(i);

a hint:
- if(f) you own the stats tbx...

help nanmean;

us
From: Andy on
"antonio ferreira" <edgar.acferreira(a)gmail.com> wrote in message <i1ple3$qrr$1(a)fred.mathworks.com>...
> Hi all,
>
> I am trying to do an average of all lines of a matrix (vel_u_filt)[600*103]. In some positions of the matrix I have NaN values. At the end I would like to have a [600*1] matrix. For this purpose I have written the following part of a code that it`s not working correctly. Can anyone give me a hint in order to do what I pretend. Regards
>
> sum=0;
> cont=0;
> for i=1:size(vel_u_filt,1)
> for j=1:size(vel_u_filt,2)
> if isnan(vel_u_filt)== 0
> sum(i)=sum+vel_u_filt;
> cont(i)=cont+1;
> end
> end
> end
>
> vel_u_DA=sum(i)/cont(i);

vel_u_filt(isnan(vel_u_filt)) = 0; % replace NaNs with 0
rowmeans = mean(vel_u_filt,2); % calculate means along the rows
From: Andy on
Whoops. I misread how you wanted to handle NaNs. You should use nanmean, as us suggested.
From: antonio ferreira on
"Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i1pm4h$ci2$1(a)fred.mathworks.com>...
> Whoops. I misread how you wanted to handle NaNs. You should use nanmean, as us suggested.

I tried to use the function nanmean for a simple example but it´s not working correctly.
I am receiving a message saying:Undefined function or method 'nanmean' for input arguments of type 'double'.
The example:
A=[1 2 3;4 5 NaN;7 8 NaN]
B=nanmean(A)

Any suggestions?regards
 |  Next  |  Last
Pages: 1 2
Prev: RF PUSH-PULL AMPLIFIER SIMULATION
Next: infinite loop