How to interleave data from 2 doubles of differing length?

2 views (last 30 days)
I want to interleave 2 doubles of differing length so that I end up with 2 doubles of the same length with empty cells so when it is output to excel it shows blanks.
Say I have these two doubles.
(in my actual code A is 57x1 and B is 446x1, not sure if that helps?)
I want to end up with
(not sure what an empty cell is for doubles, NaN maybe?)
I do not care if the result is a double or a cell matrix.

Accepted Answer

Jan on 28 Sep 2022
[C, idx] = sort([A; B]);
idxa = (idx <= numel(A));
AB = NaN(numel(C), 2);
AB(idxa, 1) = A;
AB(~idxa, 2) = B;
AB = 20×2
1420 NaN 2956 NaN NaN 2960 NaN 3152 NaN 3344 NaN 3536 NaN 3728 NaN 3920 NaN 4112 NaN 4304
Now the array is created, but this might be an open problem: "when it is output to excel it shows blanks". How do you export this to Excel?
  1 Comment
Cyrus Yousefian
Cyrus Yousefian on 28 Sep 2022
I write all of my doubles and cells to a table variable and then use writetable to export to excel.

Sign in to comment.

More Answers (0)




Community Treasure Hunt

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

Start Hunting!