Hello
I have this code and it saves the matrices in the struct, but it only saves it in the first column, I want it to save it in both columns as you can see in the picture.
I am also attaching the code
n = 2 ;
M = cell(n, 2) ;
for k = 1 : n
A = [1 2 3; 4 5 6;7 8 9];
M{k} = A ;
end
fields = {'IndivualStiffnessMAtrix','IndivualStiffnessMAtrix2'};
v =cell2struct(M,fields,n)
julian5.JPG

댓글 수: 2

Stephen23
Stephen23 2019년 11월 4일
편집: Stephen23 2019년 11월 4일
"but it only saves it in the first column, I want it to save it in both columns as you can see in the picture."
You seem to be confusing the size of a structure with the number of fields that is has: the size of a structure is totally independent of its number of fields.
Your structure actually has size 2x1, as the Variable Viewer clearly states, so it does not have a second column for "both columns" as you wrote. Your structure does have two fields though, which in the Variable Viewer are displayed as two columns, but because these are not columns of the structure your question is really quite unrelated to your example screenshot.
Chris Dan
Chris Dan 2019년 11월 4일
So, how to change it, to have two columns and matrices being saved to both columns of the structure

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

 채택된 답변

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH 2019년 11월 4일

0 개 추천

solution
n = 2 ;
M = cell(n, 2) ;
for k = 1 : n
A = [1 2 3; 4 5 6;7 8 9];
M{k,1} = A ;
M{k,2} = A ;
end
fields = {'IndivualStiffnessMAtrix','IndivualStiffnessMAtrix2'};
v =cell2struct(M,fields,n)

댓글 수: 4

Chris Dan
Chris Dan 2019년 11월 4일
This is saving to both columns of the struct, but the struct is still 2x1 with 2 fields.
You know how to make a 2x2 struct?
julian6.JPG
Stephen23
Stephen23 2019년 11월 4일
편집: Stephen23 2019년 11월 4일
"You know how to make a 2x2 struct?"
And how many fields should the 2x2 structure have?
Note that the structure in your screenshot does NOT have size 2x2, it has size 2x1 (and has 2 fields). Most likely you are confusing the size of a structure with how its fields are displayed.
here
n = 2 ;
M = cell(n, 2) ;
for k = 1 : n
A = [1 2 3; 4 5 6;7 8 9];
M{k,1} = A ;
M{k,2} = A ;
end
fields = {'IndivualStiffnessMAtrix','IndivualStiffnessMAtrix2'};
v =[cell2struct(M,fields,n) cell2struct(M,fields,n) ]
Chris Dan
Chris Dan 2019년 11월 4일
thanks :) (Y)

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Structures에 대해 자세히 알아보기

질문:

2019년 11월 4일

댓글:

2019년 11월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by