How to merge two arrays/rearrange two table colums one by one

조회 수: 1 (최근 30일)
Let's say I have tow arrays both are horizontal with the same size like:
A=[1,2,3,4,5];
B=[11,22,33,44,55];
I want to merge them so that the final array would be:
AB=[1,11,2,22,3,33,4,44,5,55];
This was my first question. And the second question is similar to the first one so that I have (one row of the table):
table=[1,2,3,4,5,11,22,33,44,55] and I want to rearragne table columns so that I would have:
table=[1,11,2,22,3,33,4,44,5,55];

채택된 답변

madhan ravi
madhan ravi 2020년 7월 2일
AB = reshape([A; B], 1, [])
  댓글 수: 2
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020년 7월 2일
Thank you. This one worked: AB = reshape([A'; B']', 1, [])
How about for table?
madhan ravi
madhan ravi 2020년 7월 2일
편집: madhan ravi 2020년 7월 2일
clear table % naming a variable table is a terrible idea!!!
TAble = table;
TAble.a = [1,2,3,4,5,11,22,33,44,55];
TAble.a = reshape(reshape(TAble.a,5,[]).', 1, [])
whos TAble

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by