Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
824 views
in Technique[技术] by (71.8m points)

matlab - Change row vector to column vector

How can I change this into a column, at the moment all 750 entries are on one row?

p = normal(1:750)-1;

I have tried:

columns = 1;
p = normal(1:750)-1;
p = p(1:columns);

I have also tried:

rows = 1000;
p = normal(1:750)-1;
p = p(1:rows)';
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is common practice in MATLAB to use the colon operator : for converting anything into a column vector. Without knowing or caring if normal is a row vector or a column vector, you can force p to be a column vector, like so:

p = p(:);

After this, p is guaranteed to be a column vector.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...