Add field to a double array?

조회 수: 15 (최근 30일)
Shuangjun
Shuangjun 2017년 10월 12일
편집: Shuangjun 2017년 10월 12일
I am working on a released code and ran into a wield error. Cited here:
...
warning('off','MATLAB:warn_r14_stucture_assignment');
obj.mu.static = obj.mu(remDim)-obj.sigma(remDim,dim)*inv(obj.sigma(dim,dim))*obj.mu(dim);
obj.mu.dynamic = obj.sigma(remDim,dim)*inv(obj.sigma(dim,dim));
warning('on','MATLAB:warn_r14_stucture_assignment');
...
Notice on second line. obj.mu is a 6x1 double array. So obj.mu(remDim) makes sense. However, how can this one be assigned to obj.mu.static as the 6x1 array can't have field.
Is that valid on old version of matlab? Can anyone explain what structure is this? What is the exact purpose of such structure.
  댓글 수: 1
KSSV
KSSV 2017년 10월 12일
How you got this error? What you were trying?

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

채택된 답변

Steven Lord
Steven Lord 2017년 10월 12일
Someone decided to ignore our warning about this behavior in the release R14SP2 Release Notes, even though we state that "In a future release of MATLAB, attempting this type of operation will throw an error instead of just displaying a warning message." That behavior became an error in release R2015b.
  댓글 수: 1
Shuangjun
Shuangjun 2017년 10월 12일
편집: Shuangjun 2017년 10월 12일
Thank you. It makes sense.

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

추가 답변 (1개)

OCDER
OCDER 2017년 10월 12일
My best guess is that someone is trying to restructure obj.mu that had a double array into one that has two fields instead. It's more of a quick fix when someone built a huge code with obj.mu = double array, but later realized it should be obj.mu.static and obj.mu.dynamic.
See comments to understand what the programmer might be thinking (but you'll have to contact the programmer to know for sure):
obj.mu = 1:6; %Oh, never mind. I should change this.....
warning('off','MATLAB:warn_r14_stucture_assignment'); %I know this will give a warning, so suppress
obj.mu.static = obj.mu(remDim)-obj.sigma(remDim,dim)*inv(obj.sigma(dim,dim))*obj.mu(dim); %override double array with "static" field
obj.mu.dynamic = obj.sigma(remDim,dim)*inv(obj.sigma(dim,dim)); %make new "dynamic" field under mu
warning('on','MATLAB:warn_r14_stucture_assignment'); %disable suppression
  댓글 수: 1
Shuangjun
Shuangjun 2017년 10월 12일
Thank you for the reasoning. As Steven mentioned, it seems to be a warning operation in the old version matlab. Indeed strange structure, double array with own field...

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

카테고리

Help CenterFile Exchange에서 Performance and Memory에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by