removing NaN values from my codes

Hi, I have these codes:
result=zeros(1,12) avedata=mean(turkeyreturn); vardata=var(turkeyreturn); N=length(turkeyreturn); for h=1:14;
A=TRBB(:,h);
BB=[A turkeyreturn A.*turkeyreturn ];
% FF=BB(0== sum(isnan(BB), 2), :);
%R(:,h)=BB((100:end),2);
y1=0;y2=0; z1=length(find(A==1)); z2=length(find(A==-1));
for k=1:length(BB) if BB(k,1)==1 y1=BB(k,3)+y1; elseif BB(k,1)==-1 y2=BB(k,2)+y2; end end
for n=length(BB)
% BB=BB(0== sum(isnan(BB), 2), :); BB=BB(isfinite(BB(:, 1)), :) column=(BB(1:end,2)) summ= sum(BB(1:end,2)) av=summ/n annualav=av*256 standard=std(column) sharpe=((annualav-rf)/standard) end
aveofones=y1/z1; aveofmione=y2/z2; buy_sell=(aveofones-aveofmione);
T_one=(aveofones-avedata)/(sqrt((vardata/N)+(vardata/z1))); T_min1=(aveofmione-avedata)/(sqrt((vardata/N)+(vardata/z2))); T_both=(aveofones-aveofmione)/(sqrt((vardata/z1)+(vardata/z1)));
% R(:,h)=FF(:,3); result(h,:)=[z1,z2,aveofones,aveofmione,buy_sell,T_one,T_min1,T_both,av,annualav, standard,sharpe]
end
how do I save the the second col um BB matrix so that I can get all the results in for loap. additionally there are some NaN values in the third column. how can I remove these row with matching cell in the first and second column please from BB matrix and save them after all.The number of NaN is different in each loap.
thanks jean

5 件のコメント

Image Analyst
Image Analyst 2014 年 1 月 9 日
Don't double space, it's must simpler than that: just highlight and click {}Code. http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
jean
jean 2014 年 1 月 17 日
what yo[u meant by double space please and where i did it?
Andreas Goser
Andreas Goser 2014 年 1 月 17 日
It means your code is not formatted and thus difficult to help you.
jean
jean 2014 年 1 月 17 日
okay thanks will do it again now
jean
jean 2014 年 1 月 17 日
Hi, I have these codes:
result=zeros(1,12)
acedata=mean(turkeyreturn);
vardata=var(turkeyreturn);
N=length(turkeyreturn);
for h=1:14;
A=TRBB(:,h);
BB=[A turkeyreturn A.*turkeyreturn ];
% FF=BB(0== sum(isnan(BB), 2), :);
%R(:,h)=BB((100:end),2);
y1=0;y2=0;
z1=length(find(A==1));
z2=length(find(A==-1));
for k=1:length(BB)
if BB(k,1)==1 y1=BB(k,3)+y1;
elseif BB(k,1)==-1
y2=BB(k,2)+y2;
end
end
for n=length(BB)
% BB=BB(0== sum(isnan(BB), 2), :);
BB=BB(isfinite(BB(:, 1)), :)
column=(BB(1:end,2))
summ= sum(BB(1:end,2))
v=summ/n
annualav=av*256
standard=std(column)
sharpe=((annualav-rf)/standard)
end
aveofones=y1/z1;
aveofmione=y2/z2;
buy_sell=(aveofones-aveofmione);
T_one=(aveofones-avedata)/(sqrt((vardata/N)+(vardata/z1)));
T_min1=(aveofmione-avedata)/(sqrt((vardata/N)+(vardata/z2)));
T_both=(aveofones-aveofmione)/(sqrt((vardata/z1)+(vardata/z1)));
% R(:,h)=FF(:,3); result(h,:)=[z1,z2,aveofones,aveofmione,buy_sell,T_one,T_min1,T_both,av,annualav, standard,sharpe]
end
how do I save the the second col um BB matrix so that I can get all the results in for loap. additionally there are some NaN values in the third column. how can I remove these row with matching cell in the first and second column please from BB matrix and save them after all.The number of NaN is different in each loap.
thanks jean

サインインしてコメントする。

回答 (1 件)

Andreas Goser
Andreas Goser 2014 年 1 月 17 日

0 投票

Without being able to understand your code and assuming you want to remove nans from the data and not your code, here is an example:
a=[1 2 nan 4 5]
x=isnan(a)
a=a(~x)

3 件のコメント

per isakson
per isakson 2014 年 1 月 17 日
.. or
a( isnan(a) ) = [];
jean
jean 2014 年 1 月 24 日
should i put it at the end of my codes. Need to remove the Nan and the value that match them in other two column.
jean
jean 2014 年 1 月 29 日
and want to save all the vales after that in one matrix and it saying matrix dimision does not match. I think the number of NaN is different from one column to another.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

質問済み:

2014 年 1 月 9 日

コメント済み:

2014 年 1 月 29 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by