필터 지우기
필터 지우기

Copy elements in a structure or a matrix?

조회 수: 5 (최근 30일)
Bárbara Matos
Bárbara Matos 2022년 3월 22일
댓글: Bárbara Matos 2022년 4월 19일
I have a matrix 2x2 presented in figure 1. For that matrix, I have a structure with all the relations. For each relation there is a parameter s11, s12, s21 and s22. (See figure 2).
When I chose an higher matrix such as 6x6, I want to copy the relationship of the 2x2 matrix for the rest fo the matrix. For example: I want to copy the relation of 1,1-2,2 for the rest of the matrix (1,2-2,3 and 1,3-2,4 and 1,4-2,5, ..., and 2,1-3,2 and ... and 5,1-6,2, etc). And the same with the other relations. (See figure 3 to understand better the relations). Those new relations will be in the same structure (figure 4).
I would like to know if there is a function or something I can use which can make this task of copying everything easier.
Because the final goal is that the user can chose the matrix he want to copy. So in this example, I want to copy the 2x2 matriz for the rest. But after this, I could chose copy the matrix 3x3 or 4x4 instead.
I know there are many functions I don't know. If you can suggest something, I would appreciate it! Thank you.

답변 (1개)

Benjamin Thompson
Benjamin Thompson 2022년 3월 22일
Here are some sample commands for creating and copying structure arrrays:
A(1,1) = struct('X', 1, 'Y', 2, 'Z', 3)
A(2,1) = struct('X', 4, 'Y', 5, 'Z', 6)
A(2,2) = struct('X', 7, 'Y', 7, 'Z', 7)
A(1,2) = struct('X', 4, 'Y', 5, 'Z', 6)
B = A
B(3,1) = 0
B(3,1:3) = struct('X', 0, 'Y', 0', 'Z', 0);
B
B(3,:)
B(3,1:3)
B(3,3)
B(3,2)
C = struct('X', 0, 'Y', 0, 'Z', 0)
C(1:3,1:3) = C
C(1:2,1:2) = A
C(1,2)
C(1,1)
You can also use cell arrays but it is harder to copy groups of elements from one cell array to another.
  댓글 수: 6
Bárbara Matos
Bárbara Matos 2022년 4월 19일
No, it is not the same. I understood how to solve the problem in the previous question. This one is difficult to explain, but I am working on it! Thank you very much.

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by