Create a new matrix from two
Afficher commentaires plus anciens
Hello everyone, i have 2 matrix A and B:
A (4X8):
0 0 0 0 0 1 0 0
0 0 1 1 1 0 1 0
0 1 0 0 0 1 0 1
1 0 1 0 0 1 0 0
B (4X3):
X1 Y1 Z1
X2 Y2 Z2
X3 Y3 Z3
X4 Y4 Z4
is it possible to create a new matrix like this?
C:
X4 Y4 Z4 X3 Y3 Z3 X2 Y2 Z2 X2 Y2 Z2 X1 Y1 Z1 X2 Y2 Z2 X3 Y3 Z3
X4 Y4 Z4 X3 Y3 Z3
X4 Y4 Z4
i tried with this code but it creates a matrix with only 3 columns:
for k=1:8
C=B(A(:,k),:);
if ~(mod(k,1))
dlmwrite('file.txt',C,'-append');
READC=dlmread('file.txt') ;
end
end
Thanks!
1 commentaire
Jan
le 14 Déc 2018
The question is not clear. What are "X1", "X2" etc.? Are they strings, symbolic variables or anyting else? The object C is not clearly defined. It cannot be a "matrix", because matrices need to have the same number of elements per row and colum. It is not clear, why you use dlmwrite and dlmread - is te indirection over the hard disk useful?
Please post valid Matlab code, which creates the inputs, and explain, which type the output should have.
Réponses (0)
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!