How can I mux or demux a bus of vectors?

11 views (last 30 days)
Lee
Lee on 17 Sep 2012
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.

Answers (2)

Kaustubha Govind
Kaustubha Govind on 17 Sep 2012
Try the Bus Selector and Bus Creator blocks.
  2 Comments
Lee
Lee on 17 Sep 2012
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 on 17 Sep 2012
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.

Sign in to comment.


Guy Rouleau
Guy Rouleau on 18 Sep 2012
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 Comments
Lee
Lee on 21 Sep 2012
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 on 21 Sep 2012
This looks good. I can't think of a better way.

Sign in to comment.

Tags

Products

Community Treasure Hunt

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

Start Hunting!