How to interleave data from 2 doubles of differing length?

조회 수: 1 (최근 30일)
Cyrus Yousefian
Cyrus Yousefian 2022년 9월 28일
댓글: Cyrus Yousefian 2022년 9월 28일
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?)
A=[1;2;11;20];
B=[3;4;5;6;7;8;9;10;12;13;14;15;16;17;18;19];
I want to end up with
(not sure what an empty cell is for doubles, NaN maybe?)
A=[1;2;blank;blank;blank;blank;blank;blank;blank;blank;11;blank;blank;blank;blank;blank;blank;blank;blank;20];
B=[blank;blank;3;4;5;6;7;8;9;10;blank;12;13;14;15;16;17;18;19];
I do not care if the result is a double or a cell matrix.

채택된 답변

Jan
Jan 2022년 9월 28일
A=[1420;2956;4492;6028];
B=[2960;3152;3344;3536;3728;3920;4112;4304;4496;4688;4880;5072;5264;5456;5648;5840];
[C, idx] = sort([A; B]);
idxa = (idx <= numel(A));
AB = NaN(numel(C), 2);
AB(idxa, 1) = A;
AB(~idxa, 2) = B;
AB
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
Cyrus Yousefian
Cyrus Yousefian 2022년 9월 28일
I write all of my doubles and cells to a table variable and then use writetable to export to excel.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Numeric Types에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by