필터 지우기
필터 지우기

Superimposing one matrix on another

조회 수: 6 (최근 30일)
Will
Will 2011년 10월 24일
m =
120 0 0 0 100
120 0 0 0 100
120 0 0 0 100
120 0 0 0 100
120 0 0 0 100
120 0 0 0 100
m1 =
85 100 170
85 170 100
100 85 170
100 170 85
170 100 85
170 85 100
Let's say I have these 2 matices. I want to create m2 from m and m1:
m2 =
120 85 100 170 100
120 85 170 100 100
120 100 85 170 100
120 100 170 85 100
120 170 100 85 100
120 170 85 100 100
How would I go about doing this?

채택된 답변

Fangjun Jiang
Fangjun Jiang 2011년 10월 24일
m2=m;
m2(m2==0)=m1

추가 답변 (1개)

the cyclist
the cyclist 2011년 10월 24일
One of a few possible ways:
m2 = m;
m2(:,2:4) = m2(:,2:4) + m1;
  댓글 수: 1
Will
Will 2011년 10월 24일
I'm trying to implement it into a loop in case I have different columns that are fixed.
Say I set: fixed = [ 0 1 1 1 0 ]. Where 0 denotes fixed columns.
for k = 1:length(fixed)
if fixed(k) == 1
m(:,?) = m(:,?) + m1;
end
end
What value would I input for the column of m?

댓글을 달려면 로그인하십시오.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by