Unable to perform assignment because brace indexing is not supported for variables of this type

1 次查看(过去 30 天)
Hello Everyone,
Hope you all are doing well.
I have a question for ADAS Programmation.
Where i am trying to create an object using the class file and Initially i have defined the variable name as left line and right lines of the road.
But now i am trying to automate the lines detected and the data populated must be segregated for the simulation purpose.
But i get an error of brace indexing is not supported.
My code is:
IdxLines = numel(simout.logsout.get("<B_x_VS_LaneBoundaries>"). ...
Values.LaneBoundaries);
for IdxLines = 1:5
sLineMajor{IdxLines,:} = simout.logsout.get("<B_x_VS_LaneBoundaries>").Values.LaneBoundaries(IdxLines);
vLineWidth{IdxLines,:} = sLineMajor(IdxLines,:).Width.Data(:); % Lane boundary Width
vLineHeadingAngle{IdxLines,:} = sLineMajor(IdxLines,:).HeadingAngle.Data;
vLineType{IdxLines,:} = sLineMajor(IdxLines,:).BoundaryType.Data(:); % Lane type 1 - Solid, 2 - Dashed
vLinexpos{IdxLines,:} = sLineMajor(IdxLines,:).Coordinates.Data(:,1,:); % xpos of the line
vLineypos{IdxLines,:} = sLineMajor(IdxLines,:).Coordinates.Data(:,2,:); % ypos of the line
vLineQuality{IdxLines,:} = sLineMajor(IdxLines,:).Strength.Data(:); % Represents the Line Quality,
oLine{IdxLines,:} = roadLines(vLineWidth,10,vLineHeadingAngle, ...
vLineQuality,vLineType,vLinexpos,vLineypos);
end
Class def file:
classdef roadLines
% Class for defining line properties
properties (Access = public)
Width; % Width of the Line specified on the simulink file
viewRange;
headingAngle;
Quality;
Type; % Type of Line dashed, double lines, solid, dotted and non continuous
xPos; % Y Position of the Line
yPos; % X Position of the Line
Style; % Derived based on the type
end
methods
% Constructor
function obj = roadLines(Width,viewRange, headingAngle, ...
Quality, vType, xPos, yPos)
obj.Width = Width;
obj.viewRange = viewRange;
obj.headingAngle = headingAngle;
% obj.curvature = curvature; % Currently
% commented out as it is not used anywhere
% obj.curvatureDerviative = curvatureDerviative;
obj.Quality = Quality;
obj.Type = vType;
obj.xPos = xPos;
obj.yPos = yPos;
obj.Style = setStyle(obj);
end
function cDisplayStyle = setStyle(lineProperties)
vType = lineProperties.Type;
% Initialize the output cell array with nan values
cDisplayStyle = cell(length(vType), 1);
% Loop over each time step
for idx_Time = 1:numel(vType)
if vType(idx_Time) == 1 % 1= Solid line
cDisplayStyle{idx_Time} = '-';
elseif vType(idx_Time) == 2 % 2 = Dashed line
cDisplayStyle{idx_Time} = '--';
else % Any other line type is affected to "-." style
cDisplayStyle{idx_Time} = '-.';
end
end
end % end displayLineStyle
end
end
I am sorry i cannot provide the data's as it is confidential.
but i can say that the data's inside lane boundaries are in the format of structs and inside it is the format of time series and each time series is specified as a vector of 3 Dimensioned matrix.
So basically my idea is. That my code needs to extract data's in to multiple objects Like Line1, Line2, Line3 and etc. and the object collections must be formed in to a struct.
The Struct formation is already done and object collection is also done but i am just stuck in this automatic indexing incrementation.
and the incrementation of number must occur automatically.
Thank you for all the answers and support in Advance.
If my question is not clear kindly comment and i will try to clarify it.
  1 个评论
VBBV
VBBV 2024-3-25
编辑:VBBV 2024-3-25
The RHS of first line inside the loop returns a scalar structure from which you can extract field data. If you want a vector form as in non-scalar structures, then use regular brackets () instead of { }

请先登录,再进行评论。

采纳的回答

VBBV
VBBV 2024-3-25
编辑:VBBV 2024-3-25
Try the folliowing
sLineMajor = simout.logsout.get("<B_x_VS_LaneBoundaries>").Values.LaneBoundaries(IdxLines);
vLineWidth{IdxLines,:} = sLineMajor.Width.Data(:); % Lane boundary Width
vLineHeadingAngle{IdxLines,:} = sLineMajor.HeadingAngle.Data;
  4 个评论
VBBV
VBBV 2024-3-25
编辑:VBBV 2024-3-25
Since you want code to extract data from struct fields as objects , it's better to use ( ) than { } However, the field data of all structs will be present in remaining variables, pls check vLineWidth ,it will contain data from all 4 structs
sLineMajor(IdxLines) = simout.logsout.get("<B_x_VS_LaneBoundaries>").Values.LaneBoundaries(IdxLines);
vLineWidth{IdxLines,:} = sLineMajor(IdxLines).Width.Data(:)
Ram Prasanth
Ram Prasanth 2024-3-26
Hi @VBBV,
Thank you for your Help. it works andbelow is the screenshot of the data stored in the cell arrays.
Furthermore i have found much more efficient way to create the object. Below is the code for that. Please provide your advice if it is ok or is there much better way for it.
IdxLines = numel(simout.logsout.get("<B_x_VS_LaneBoundaries>"). ...
Values.LaneBoundaries);
for IdxLines = 1:IdxLines
sLineMajor= simout.logsout.get("<B_x_VS_LaneBoundaries>").Values.LaneBoundaries(IdxLines);
vLineWidth = sLineMajor.Width.Data(:); % Lane boundary Width
vLineHeadingAngle = sLineMajor.HeadingAngle.Data;
vLineType = sLineMajor.BoundaryType.Data(:); % Lane type 1 - Solid, 2 - Dashed
vLinexpos = sLineMajor.Coordinates.Data(:,1,:); % xpos of the line
vLineypos = sLineMajor.Coordinates.Data(:,2,:); % ypos of the line
vLineQuality = sLineMajor.Strength.Data(:); % Represents the Line Quality,
oLine(IdxLines,:) = roadLines(vLineWidth,10,vLineHeadingAngle, ...
vLineQuality,vLineType,vLinexpos,vLineypos);
end
Here is how the object is extracted directly.
Thank you.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Testing Frameworks 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by