Sharing the values between vectors
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!