I thought this could be done on one line, but I was wrong. See Solution below:
Given (the added line helps me debug my indexing below):
>> A = [NaN 1 2 ; 3 NaN 4; NaN 5 6; 7 8 NaN] A = NaN 1 2 3 NaN 4 NaN 5 6 7 8 NaN
Then:
>> Atrans = A'; >> B = reshape( Atrans(~isnan(Atrans)) ,[],size(Atrans,2))' B = 1 2 3 4 5 6 7 8
By the way, Matlab's Italoma for performing a simple logical check in an array in a logical indexing operation is very common and incredibly useful. Archetypal example:
>> x(x>0) %This returns a 1D column vector of all values of x %which are greater than 0, regardless of the initial %size of x. Multidimensional inputs are unwrapped %column-first
Everything else above is handling size and size.
source share