How can I calculate dependent properties and assign them to the object?

4 ビュー (過去 30 日間)
J. Hu
J. Hu 2013 年 9 月 28 日
回答済み: Yvo Putter 2018 年 1 月 15 日
Given a property for an object, need to calculate some values and assign them to the properties of the same object. I use following code but it does not work, showing three error messages.
classdef GCSSetup
properties
Preference
end
properties (Dependent)
VDir
NDir
EDir
EDirAzDeg
iCol
end
methods
function [] = GCSDefine(GCS)
% GCSPreference = 'VZ_NY'; % Vertical-Z / North -Y
switch GCS.Preference
case 'VZ_NY'
GCS.VDir = 'ZDir'; % System coordinate frame for Vertical direction
GCS.NDir = 'YDir'; % System coordinate frame for North direction
GCS.EDir = 'XDir'; % System coordinate frame for East direction
GCS.EDirAzDeg = 90;% Azimuth angle for east direction
% XDirDeg = 90; % Azimuth for the X-frame direction in global coordinate system
case ''
end
% iCol is the index to
if strcmp(GCS.VDir,'ZDir')==1, GCS.iCol=3;
elseif strcmp(GCS.VDir,'YDir')==1, GCS.iCol=2;
elseif strcmp(GCS.VDir,'XDir')==1, GCS.iCol=1;
else
end
end
end
end
Please help. Thanks...
  2 件のコメント
Image Analyst
Image Analyst 2013 年 9 月 28 日
How are you instantiating and calling this? Please attach your classdef file and the test script that you use to call it.
J. Hu
J. Hu 2013 年 9 月 29 日
編集済み: Image Analyst 2013 年 9 月 29 日
I used following code to call the function:
GCSPreference = 'VZ_NY'; % Vertical-Z / North -Y
GCS = GCSSetup(GCSPreference);

サインインしてコメントする。

回答 (2 件)

Matt J
Matt J 2013 年 9 月 29 日
編集済み: Matt J 2013 年 9 月 29 日
You cannot store actual data to a Dependent property as you try to do, for example, in
GCS.VDir = 'ZDir';
The whole point of a Dependent property is that it never actually stores data.
  5 件のコメント
Matt J
Matt J 2013 年 9 月 30 日
編集済み: Matt J 2013 年 9 月 30 日
I don't see what's strange. The only way to access Dependent properties is to define set() and get() methods that generate on-the-fly values for the property. You do not appear to have done that.
per isakson
per isakson 2013 年 10 月 6 日
Here (R2013a, Win7) your code returns the following error
In class 'GCSSetup', no set method is defined for Dependent property
'VDir'. A Dependent property needs a set method to assign its value.
Error in GCSSetup (line 24)
Obj.VDir = 'ZDir'; % System coordinate frame for Vertical direction

サインインしてコメントする。


Yvo Putter
Yvo Putter 2018 年 1 月 15 日
For future readers,
To do this you don't need dependent properties but the following, as outlined in this thread:
properties (SetAccess = private)

カテゴリ

Help Center および File ExchangeConstruct and Work with Object Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by