Custom Data Type in arrays

1 vue (au cours des 30 derniers jours)
Iban
Iban le 24 Mai 2011
Hi,
I have defined a Custom Data Type like this:
%tDistanceFloat32
tDistanceFloat32 = Simulink.AliasType;
tDistanceFloat32.BaseType = 'single';
tDistanceFloat32.Description = '[m]';
And a parameter like this:
% NumberOfBalises:
NumberOfBalises = Simulink.Parameter;
NumberOfBalises.DataType = 'int32';
NumberOfBalises.Value = 9;
NumberOfBalises.Description = 'Numero de balizas que hay en el trayecto';
Now, I want to define a vector named 'BalisesPosition' that has 9 elements of type 'tDistanceFloat32', so I have written this:
BalisesPosition = zeros (1,NumberOfBalises.Value);
Till now, this works fine, but the problem comes now. I want to set the values of the vector, wich, as I said before, have to be of type 'tDistanceFloat32', so I type this:
BalisesPosition(1,1) = tDistanceFloat32(0.0);
BalisesPosition(1,2) = tDistanceFloat32(1500.0);
BalisesPosition(1,3) = tDistanceFloat32(2000.0);
...
This gives the following error: '??? Subscript indices must either be real positive integers or logicals.' And if I type the following:
BalisesPosition(1,1) = tDistanceFloat32.BaseType(0.0);
BalisesPosition(1,2) = tDistanceFloat32.BaseType(1500.0);
BalisesPosition(1,3) = tDistanceFloat32.BaseType(2000.0);
...
It gives this error: '??? Index exceeds matrix dimensions.'
Does anybody know where the problem can be? if I type this:
BalisesPosition(1,1) = single(0.0);
BalisesPosition(1,2) = single(1500.0);
BalisesPosition(1,3) = single(2000.0);
...
it works, but I don´t want that, I want to use the tDistanceFloat32' type.
Can anybody help me?

Réponse acceptée

Fangjun Jiang
Fangjun Jiang le 24 Mai 2011
Is BalisesPosition a signal or parameter?
If it is a parameter,
BalisesPosition=Simulink.Parameter;
BalisesPosition.Value=zeros(1, NumberOfBalises.Value);
BalisesPosition.DataType='tDistanceFloat32';
If it is a signal,
BalisesPosition=Simulink.Signal;
BalisesPosition.InitialValue=num2str(zeros(1, NumberOfBalises.Value));
BalisesPosition.DataType='tDistanceFloat32';

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by