Trying to form a large matrix from 1 small matrix

1 次查看(过去 30 天)
Here is the code:
clear all
clc
syms s x
he = 1/22
k_e = [12/(he^3) 12/(he^3) 6/(he^2) 6/(he^2);
12/(he^3) 12/(he^3) -6/(he^2) -6/(he^2);
6/(he^2) -6/(he^2) 4/(he^2) 2/(he^2);
6/(he^2) -6/(he^2) 2/(he^2) 4/(he^2)];
k_g = zeros(46)
for r = 1:23
for c = 1:23
if c = 21
continue
end
if r = 21
continue
end
k_g(r+2,c+2) = k_e;
end
end
k_g
The aim is to insert k_e in k_g after 2 rows and 2 columns and sum the merging values
By "sum mergin vaues", I mean that first time k_e is in k_g, it takes 1,1 to 4,4.
The next time, k_e is inserted starting from 3,3 position and the values at 3,3 3,4 4,3 4,4 are summed with the previous k_e in k_g.
Just as an example, a 2x2 (k_e) which looks like this:
a = [A B C;
D E F;
G H I];
Which added again and again in to b should look like this:
b = [A B C 0 0 0 0;
D E F 0 0 0 0;
G H I+A B C 0 0;
0 0 D E F 0 0;
0 0 G H I+A B C;
0 0 0 0 D E F;
0 0 0 0 G H I];
I hope it clarifies the problem.
Only this time, the a is a 4x4 and b is 46x46 and a is inserted at every (n+2)th row and (n+2)th column
Thanks

采纳的回答

Alex Hanes
Alex Hanes 2022-10-24
编辑:Alex Hanes 2022-10-25
If I’m following correctly, the following code should get you in the right direction:
k_e = 2*ones(4,4); % place-holder for your symbolic ke
dimB = 46; % set dimension of B-array
B0 = zeros(dimB); % pre-allocate
B = zeros(dimB); % pre-allocate
[m,n] = size(k_e);
B0(1:m,1:n) = k_e; % store k_e in first position
for k = 0:2:dimB-m
B = B + circshift(circshift(B0,k,1),k,2);
end

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by