필터 지우기
필터 지우기

Trying to form a large matrix from 1 small matrix

조회 수: 1 (최근 30일)
Saim
Saim 2022년 10월 24일
편집: Alex Hanes 2022년 10월 25일
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