How to attach multiple matrices to a single matrix?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
niniki
il 18 Mar 2022
Risposto: Davide Masiello
il 18 Mar 2022
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 Commenti
Risposta accettata
Davide Masiello
il 18 Mar 2022
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 Commenti
Più risposte (1)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!