Hi all, I'm looking for a way to create a column vector using something similar to "linspace". I saw that this is used to create ROW vectors with a starting point, an ending point and an interval (2,10,0.1). I should do a column vector for 2 to 0 with an interval of -0.1. Every time I try to do that I receive the "error (?)" Empty matrix: 1-by-0. How can I solve the problem? Is there a command as linspace for column row?

 채택된 답변

W. Owen Brimijoin
W. Owen Brimijoin 2015년 2월 25일

3 개 추천

There are two ways to approach this and I think you're conflating the two:
Here's one option
colvec = [2:-.1:0]';
Here's the other:
colvec = linspace(2,0,21)';
Note that in the first example, you are specifying the interval (which must be negative) and this determines how many elements you end up with. In the second you are explicitly telling linspace how many elements you want (that's the 3rd argument for linspace) and this determines the interval between them.
In both cases the output is a row vector, so the transpose (') operator is used.

댓글 수: 7

AnnaMaria Accardo
AnnaMaria Accardo 2015년 2월 25일
So, just to be sure, the (') means "transpose of the vector", right? As I said before, I'm new in matlab and I'm studying it
W. Owen Brimijoin
W. Owen Brimijoin 2015년 2월 25일
yes, putting that symbol in there will turn a row vector into a column, and vice versa. This works for matrices too, effectively rotating them by 90 degrees.
AnnaMaria Accardo
AnnaMaria Accardo 2015년 2월 25일
Perfect. Thanks. I'm sorry if the question was too stupid for you. I'm a very beginner student
@W. Owen Brimijoin: 2:-.1:0 is a vector already, such that additional square brackets are not required. But round parenthesis are needed for the transpose:
colvec = (2:-.1:0).';
Jos (10584)
Jos (10584) 2015년 2월 25일
편집: Jos (10584) 2015년 2월 25일
@ W. Omen Brimijoin : Please note that transpose is not the same as rotating over 90 degrees ;-)
M = [1 2 3 ; 4 5 6]
rot90(M)
M.'
Adam
Adam 2015년 2월 25일
It's the same thing as a sensible 90-degree clockwise rotation rather than a Matlab counter-clockwise rotation!
W. Owen Brimijoin
W. Owen Brimijoin 2015년 2월 26일
Jan Simon, thank you, you are right that square brackets are not needed here! And Jos, rotation is a loaded word, for sure. In writing my response I had considered and discarded phrases like 'tipped upright,' 'flopped downward,' 'flipped down' and... oh I don't know... 'dangled down?'
The use of "rotation" seemed like a compromise between being intuitive and being correct. I still don't know what's best here!
best,
-Owen.
>
ps. Now I think I like being referred to as Omen Brimijoin. It has a certain dire ring to it.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Sushma
Sushma 2025년 3월 14일
편집: Torsten 2025년 3월 14일

0 개 추천

लिनस्पेस और : ऑपरेटर दोनों ही पंक्ति सदिश बनाते हैं। लेकिन क्या होगा यदि आपको रैखिक रूप से स्थानित स्तंभ सदिश की आवश्यकता है? ट्रांसपोज़ ऑपरेटर (') पंक्ति सदिश को स्तंभ सदिश में परिवर्तित करता है। x = 1:3 x = 1 2 3 x = x' x = 1 2 3 कार्य ट्रांसपोज़ ऑपरेटर का उपयोग करके पंक्ति सदिश से स्तंभ सदिश में b को ट्रांसपोज़ करें।
The linspace and : operators both create row vectors. But what if you need a linearly spaced column vector? The transpose operator (') converts a row vector to a column vector. x = 1:3 x = 1 2 3 x = x' x = 1 2 3 Function Transpose b from a row vector to a column vector using the transpose operator.

카테고리

도움말 센터File Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

태그

질문:

2015년 2월 25일

편집:

2025년 3월 14일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by