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:
filling matrix with a vector in order

Subject: filling matrix with a vector in order

From: xplore29

Date: 21 Mar, 2013 20:02:05

Message: 1 of 2

M = [1 1 0;1 0 0;0 1 0]
V = [8 2 3 4 5]
where
 length(V)=length(find(M==0))

From M and V i want to create X

X = [1 1 8;1 2 3;4 1 5]

i-e replacing zero in M by the elements in V in the order from
           Left to Right and Top to Bottom

Subject: filling matrix with a vector in order

From: dpb

Date: 21 Mar, 2013 20:57:51

Message: 2 of 2

On 3/21/2013 3:02 PM, xplore29 wrote:
> M = [1 1 0;1 0 0;0 1 0]
> V = [8 2 3 4 5]
> where
> length(V)=length(find(M==0))
>
> From M and V i want to create X
> X = [1 1 8;1 2 3;4 1 5]
>
> i-e replacing zero in M by the elements in V in the order from Left to
> Right and Top to Bottom

 >> N=M';N(N==0)=V;M=N'
M =
      1 1 8
      1 2 3
      4 1 5
 >>

--

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