Column vector with interval

840 Ansichten (letzte 30 Tage)
AnnaMaria Accardo
AnnaMaria Accardo am 25 Feb. 2015
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?

Akzeptierte Antwort

W. Owen Brimijoin
W. Owen Brimijoin am 25 Feb. 2015
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 Kommentare
Adam
Adam am 25 Feb. 2015
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 am 26 Feb. 2015
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 25 Feb. 2015
v=2:-0.1:0
v=v'

Kategorien

Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by