creating a structure from a bus object in matlab

I have a busobject which has elements and then each element either has a datatype of primitive (uint8 single, uint16) or has a datatype which is another bus object. i wanted to parse this but i get the error 'Function cannot be indexed using {} or .indexing' when i use a nested function since i need to use the bsu objects from the workspace. this is my code:
function s_func_parse(component_name,counter)
length_bus=length(component_name.Elements);
for i=1:length_bus
primitive_component{1,counter}=strcat(component_name.Elements(i).Datatype,'.');
if(strcmp(component_name.Elements(i).Datatype,'uint8')~=1 || strcmp(component_name.Elements(i).Datatype,'single')~=1 || strcmp(component_name.Elements(i).Datatype,'uint16')~=1 || strcmp(component_name.Elements(i).Datatype,'uint32')~=1)
new_component=char(busobject.Elements(i).Datatype);
s_func_parse(new_component,counter);
else
primitive_component{1,counter}=strcat(primitive_component,busobject.Element(i));
end;
end;
assignin('base', 'primitive_component', primitive_component);
end
where component_name is the main bus object and counter determines the total number of primitives i am having and this value i already know.
for now am not able to solve this problem so I thought of converting the bus object to a structure which has all the data inside it. Is it possible?

댓글 수: 1

Jan
Jan 2015년 3월 20일
Please post the complete error message. Most of all the line, which causes the error cannot be guessed by the readers.

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

 채택된 답변

Sebastian Castro
Sebastian Castro 2015년 3월 20일

0 개 추천

You can convert buses to structures using this function:
- Sebastian

댓글 수: 1

I solved the problem by creating a custom struct with data i needed but i think your solution will work as well. have not yet tried it but saw the example and looks like it works so i will accept it for now.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Simulink에 대해 자세히 알아보기

질문:

2015년 3월 20일

댓글:

2015년 3월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by