필터 지우기
필터 지우기

Merge two different size matrices into each other?

조회 수: 1 (최근 30일)
Cladio Andrea
Cladio Andrea 2015년 2월 25일
편집: Cladio Andrea 2015년 2월 25일
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개)

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by