What's function does replace LINALG::SUBSTITUTE (A,B,m,n)?

I'm searching for matlab function which replaces linalg::substitute (A,B,m,n); it allows me replace a part of original matrix A, with a submatrix B, starting from A raw m and A column n.
Thank you.

Answers (1)

Hi,
you can use this function:
function result = linalg_substitute(A,B,m,n)
[mA, nA] = size(A);
[mB, nB] = size(B);
result = A;
if mB+m-1 > mA || nB+n-1 > nA %Ignore values out of range
return
else
result(m:mB+m-1, n:nB+n-1) = B;
end
end
Result is for example:
>> A = zeros(5)
A =
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
>> B = ones(3)
B =
1 1 1
1 1 1
1 1 1
>> C = linalg_substitute(A,B,2,2)
C =
0 0 0 0 0
0 1 1 1 0
0 1 1 1 0
0 1 1 1 0
0 0 0 0 0
Simply save the function as linalg_substitute.m in your Matlab path. Then you can use it always you need it.
Best regards
Stephan

Categories

Find more on Debugging and Improving Code in Help Center and File Exchange

Asked:

on 2 Jan 2019

Edited:

on 3 Jan 2019

Community Treasure Hunt

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

Start Hunting!