MATLAB Answers

0

How do I create a unit vector with multiple rows

Asked by Adam Wright on 17 Apr 2019
Latest activity Commented on by Adam Wright on 17 Apr 2019
I want to create a unit vector with multiple rows, but only one input line.
For example I want an output like this: [14 15 16; 12 13 14].
I tried to put input of [14;12]:[1;1]:[16;14] and just got the output of [14,15,16] instead of mutiple rows.
All the vectors will be the same length so that won't be an issue.

  0 Comments

Sign in to comment.

1 Answer

Answer by madhan ravi
on 17 Apr 2019
 Accepted Answer

[14:16;12:14]

  3 Comments

This works for a 2 row array, but I was going increase the number of rows. So I need something that would work regardless of the number of rows.
For example one output could be:
[14 15 16; 2 3 4; 48 49 50; 21 22 23]
a=[14;2;48;21]
b=[16;4;50;23]
cell2mat(arrayfun(@(x,y)x:y,a,b,'un',0))
Perfect. Thank you

Sign in to comment.