Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
transform vector in matrix with more elements

Subject: transform vector in matrix with more elements

From: Emily Bauner

Date: 23 May, 2010 22:22:04

Message: 1 of 1

Hi all,
I'm looking for a fast way to distribute vector elements in a given matrix such that identical elements are listed in the same matrix row; the tricky part is that the vector has fewer elements than the matrix. For instance, assume that I have vector A:

A = [1 2 2 3 3 3 4 4 4 4 5 5 5 5 6 6 6 7 7 8]

I need some command that gives me matrix B, where B is
B =
     1 0 0 0
     2 2 0 0
     3 3 3 0
     4 4 4 4
     5 5 5 5
     6 6 6 0
     7 7 0 0
     8 0 0 0

This operation is very time-sensitive in my code as it has to be done often and with varying vector/matrix sizes. Therefore I would like to avoid a loop if at all possible.
Any ideas would be greatly appreciated.

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us