MATLAB: Combining two different size variables into one matrix

different sizematrixnan'sreplacing

Hi!
I have two variables of different size. Let's suppose A is the size of 1×5 and B is the size of 1×8. I want to make a matrix where the first row will be A, and the second raw will be B. The matrix should be the size of 2×8 where the last columns of the first row are replaced with NaNs. For example:
A = [1 2 3 4 5]
B = [1 2 3 4 5 6 7 8]
C = [1 2 3 4 5 NaN NaN NaN; 1 2 3 4 5 6 7 8]
How can I do this?
Thanks!

Best Answer

The simplest solution is to download this:
and then all you need is this:
>> A = [1,2,3,4,5];
>> B = [1,2,3,4,5,6,7,8];
>> C = padcat(A,B)
C =
1 2 3 4 5 NaN NaN NaN
1 2 3 4 5 6 7 8