Custom Data Type in arrays
1 view (last 30 days)
Show older comments
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?
0 Comments
Accepted Answer
Fangjun Jiang
on 24 May 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';
0 Comments
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!