Sharing the values between vectors

1 回表示 (過去 30 日間)
PChoppala
PChoppala 2013 年 7 月 31 日
Hi
I will appreciate your support on this:
I have a 3 x 9 matrix f with some finite and non-finite values. I have to manipulate f so that I will have only finite values (that is easy), and each row will have Ns finite values (as shown in temp). N is apparently divisible by Ns. Essentially, if the finite number of values in a row(s) of f is greater than Ns, they have to be adjusted amongst the other rows.
N=9; Ns=3;
f=[1,2,6,7,8,nan,nan,nan,nan;3,4,nan,nan,nan,nan,nan,nan,nan;5,9,nan,nan,nan,nan,nan,nan,nan];
temp=[1 2 6 ; 3 4 7 ; 5 9 8 ];
It could be simple, but I am now able to come up with an elegant solution. Any suggestion on how to do this?
Thank you

採用された回答

Andrei Bobrov
Andrei Bobrov 2013 年 7 月 31 日
編集済み: Andrei Bobrov 2013 年 7 月 31 日
f =[1,2,6,7,8,nan,nan,nan,nan;
3,4,nan,nan,nan,nan,nan,nan,nan;
5,9,nan,nan,nan,nan,nan,nan,nan];
out = nan(size(f,1),Ns);
d = f(~isnan(f));
try
out(1:numel(d)) = d;
catch
msg = lasterror.message
end
  1 件のコメント
PChoppala
PChoppala 2013 年 7 月 31 日
Thank you very much.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by