How can I mux or demux a bus of vectors?

I'd like to have a top level model which contains bus type connections between subsystems. The bus contains both vectors of the same length. Inside subsystems, I'd like to be able to process data either using the vectors as a whole, or by selecting a single index from each vector combined together as a bus of scalars. I'm stuck on the latter issue. I'm looking for a demux block or selector for a bus of vectors. Is there a good way to do this? I have the same need for muxing to create bus of vectors.

답변 (2개)

Kaustubha Govind
Kaustubha Govind 2012년 9월 17일

0 개 추천

Try the Bus Selector and Bus Creator blocks.

댓글 수: 2

Lee
Lee 2012년 9월 17일
Yes, but I may be missing something on how to do this process efficiently. For the bus selector, for example, let's say that I have m bus signals, and each is n long. I could use a bus selector to select all of the signals from the bus. I could then demux each of the vectors into n signals. I could then combine one signal from each of the muxes into one of n bus creators. Is their an easier way to do this?
I think I could also use a matrix as my bus, to make this process easier, but then I lose the benefit of having the named signals in the bus.
Kaustubha Govind
Kaustubha Govind 2012년 9월 17일
Lee: I think you might be able to use the Bus To Vector block to convert your bus of scalars to a vector. But you will need to use a Bus Creator for the reverse process.

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

Guy Rouleau
Guy Rouleau 2012년 9월 18일

0 개 추천

You are making a bus of vectors. Based on your description you should go for an array of buses.
Then you could use the For Each subsystem to process the elements more efficiently.
See:

댓글 수: 2

What I'm possibly stuck on is converting between the two formats. Internally in a subsystem, an array of buses works well. However, I would like to define an interface to this subsystem that uses a bus of vectors, for efficient processing outside of the subsystem. Right now, the best conversion I have is with a matlab function that looks like:
function y = fcn(u, n)
%#codegen
% trying to find a better way to do this
y = repmat(struct('var1',uint16(0),...
'var2',0),n,1); % etc
for i = 1:n
y(i).var1 = u.var1(i);
y(i).var2 = u.var2(i);
end
Does this seem like the best way to do this?
Guy Rouleau
Guy Rouleau 2012년 9월 21일
This looks good. I can't think of a better way.

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

카테고리

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

제품

태그

질문:

Lee
2012년 9월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by