How to attach multiple matrices to a single matrix?
조회 수: 1 (최근 30일)
이전 댓글 표시
There are A, B, C, and D matrices of 100x1 size.
I would like to combine this data into a matrix of 400x1 size.
However, the conditions must be followed by 5x1 of each matrix.
A = [1,2,3,4,5,6,7,8,9,10....]
B = [a,b,c,d,e,f,g,h,i,j...]
C = [11,22,33,44,55,66,77,88,99...]
D = [A,B,C,D,E,F,G,H,I,J...]
Assuming that it's like this,
F = [1,2,3,4,5,a,b,c,d,e,11,22,33,44,55,A,B,C,D,E,...]
I'm going to make these results.
The method I tried was:
Inside the for loop
Use the fseek function to add 'offset=0' first and then 'offset=5'.
I saved it using the spread function.
I got the result I wanted.
I'm wondering what else you can do.
댓글 수: 0
채택된 답변
Davide Masiello
2022년 3월 18일
The code below will keep repeating the values form each array 5 by 5, i.e. it won't use only the first 5 values of each array.
In the example below I used 1x15 arrays (I don't know what's after "z" in B and C). Just replace your array and it should work
clear,clc
A = 1:15
B = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o'}
C = 11:11:165
D = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O'}
A = reshape(A,5,[]);
B = reshape(B,5,[]);
C = reshape(C,5,[]);
D = reshape(D,5,[]);
OUT = [num2cell(A);B;num2cell(C);D];
OUT = OUT(:)'
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!