Create a new matrix from two
显示 更早的评论
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 个评论
Jan
2018-12-14
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.
回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!