Sharing the values between vectors

1 view (last 30 days)
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

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 31 Jul 2013
Edited: Andrei Bobrov on 31 Jul 2013
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

More Answers (0)

Community Treasure Hunt

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

Start Hunting!