Merge two different size matrices into each other?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello everyone, i have matrices
A = [0, 1, 2, 3, 4, 5, 7, 10];
B = [2, 1;5,5;7,8];
C(:,1) = A;
C(end,2) = 0;
% ind = arrayfun(@(x)(find(x==A)), B(:,1));
% or
ind = find(ismember(A,B(:,1)))
C(ind,2) = A(ind);
what i have in the end is a matrix like
1 0
2 2
3 0
4 0
5 5
7 7
10 0
the point was to find B(:,1) numbers in A and insert the number if it exists, if not insert 0, but what i wanna do is that now : i want to create a 3rd element in matrix C also showing the corresponding elements of BB(:,1) which is BB(:,2) in our case, as a result C should be like that
1 0 0
2 2 1
3 0 0
4 0 0
5 5 5
7 7 8
10 0 0
as you see the corresponding values of BB matrix should be on the 3rd row of C, can anyone help me please?
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!