matlab의 struct를 table로 전환해보자

in kr •  7 years ago 

우선 moments라는 struct가 있다.

moment=
struct with fields:

     dy: 0.9040
     dc: 0.6901
     pinfobs: 0.7850
     corYI: -0.2466
     corYC: 0.5686
    arI: 0.7623
    arY: 0.3161
    cyc: -0.0279

이 struct는 다양한 변수들과 그 값으로 이루어져 있다. 이 struct는 연산에는 편리하지만 display 용도로는 그리 좋지 않다. struct2table는 이를 편하게 해 준다.

TT = struct2table(moment2);

이 명령어는 위의 struct를 TT라는 이름의 표로 만들어준다 .
다만 이 TT는 세로가 아니라 가로로 이루어진 표다.

이걸 세로표로 만들고 싶으면 밑에 4 라인을 더 넣어주면 된다.

    AA = table2array(TT);
    bench = array2table(AA');
    bench.Properties.RowNames = TT.Properties.VariableNames;
    bench.Properties.VariableNames = {'value'};

첫줄은 table을 다시 array로 만듦.
두번째는 array AA를 transpose 한 후 다시 table로 만듦.
나머지 두 줄은 table에 이름을 붙여주는 간단한 작업.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!