MATLAB Answers

Ayob

How to convert a vector to a row of a matrix and resize it at the same time in a special situation?

Asked by Ayob
on 19 Apr 2013
Accepted Answer by Matt J

I want to convert a vector to a row of a matrix in a special situation which is necessary to resize it too as I explain.

for example:

vector A=[1 2 3]

should be the second row of matrix B in a special situation as shown below,as you see in the second row of the matrix B,after every two element zero we have a element of vector A.

B=[a b c d e f g h i;
0 0 1 0,0 2 0 0 3;
a1 b1 c1 d1 e1 f1 g1 h1 i1;
.. .. .. .. .. .. .. .. ..;]

My program is a large one and I need the way which is fast.

  0 Comments

Products

No products are associated with this question.

2 Answers

Answer by Matt J
on 19 Apr 2013
 Accepted answer
 B(2,:)=0;
 B(2,3:3:end)=A;

  1 Comment

Ayob
on 19 Apr 2013

Yes,it works


Answer by Azzi Abdelmalek
on 19 Apr 2013
   A=[1 2 3]
B=[5 5 5 5 5 5 5 5 5;0 0 0 0 0 0 0 0 0;4 4 4 4 4 4 4 4 4]
n=size(B,2)
id=fix(n/3);
B(2,id:id:n)=A

  1 Comment

Ayob
on 19 Apr 2013

Good but not as much Matt. method.


Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply today