Hello
I need some help to change a matrix with a function in a m. file. which is called "add(A,B,I)"
A is the matrix, B is the new values and I is the position
A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16];
B = [99 98; 22 23];
I = [3,2]
The function should return a result that looks like this
[1 2 3 4; 5 6 7 8; 9 99 98 12; 13 21 23 16]
I have tried google to find help with the coding in the m. file. Can anybody help me with this problem?

댓글 수: 2

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 21일
Can you explain?
the cyclist
the cyclist 2015년 8월 21일
편집: the cyclist 2015년 8월 21일
The algorithm to get the result from the input is not clear (at least not to me).
EDIT: I think I figured out what you mean. You want to embed B into A, beginning at the indices defined by I. If that is what you mean, my answer does that.
I suggest you do not call your function "add" which is a MATLAB keyword. Maybe call it "insertSubmatrix" or something like that.

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

 채택된 답변

the cyclist
the cyclist 2015년 8월 21일

0 개 추천

I think I figured out what you mean. Does this do what you want?
[m,n] = size(B);
A(I(1):(I(1)+(m-1)),I(2):(I(2)+(n-1))) = B

댓글 수: 1

Mathias Eriksen
Mathias Eriksen 2015년 8월 21일
It worked. Thank you for your help, I appreciate it (Thumps up)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기

태그

질문:

2015년 8월 21일

댓글:

2015년 8월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by