필터 지우기
필터 지우기

Update matrix from matrix

조회 수: 1 (최근 30일)
Gavanpreet Singh Bhatia
Gavanpreet Singh Bhatia 2018년 1월 30일
답변: Tasneem 2022년 7월 12일
M1 =
1 --> Position 1
2 --> Position 2
1 --> Position 3
2 --> Position 4
M2 =
2 1 3 4
Hi All,
I need your help in coding for a simple program.
I have two Matrices (or Arrays) and I want to update M2 according to M1.
This i tell you how, for instance, whatever number is present in M1 third position gets updated in every index of M2 where number 3 is present. And same goes for all positions of M2.
So, my desired result would be like this {M2 = 2 1 1 2 }
Please help.

답변 (1개)

Tasneem
Tasneem 2022년 7월 12일
It is my understanding that you have two Arrays M1 & M2. M2 contains indexes and you want to update M2 according to the values present at those indexes in M1.
The MATLAB code for this is given below and this code is giving the desired result.
m1 = [1,2,1,2];
m2 = [2,1,3,4];
m2(1:length(m2)) = m1(m2);

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by