atwo to a one dimentional vector in Matlab

1 回表示 (過去 30 日間)
Bob
Bob 2012 年 5 月 23 日
How would I get a one dimentional vector in Matlab, so that when I type size(x) the size is, for example, 10 and not 1 by 10?
  1 件のコメント
James Tursa
James Tursa 2012 年 5 月 23 日
Maybe use the numel function instead.

サインインしてコメントする。

回答 (3 件)

Sean de Wolski
Sean de Wolski 2012 年 5 月 23 日
That is not possible unless you define your own class that will internally store the vector as a 1x10 but display 10 when queried for size or if you write your own size function.
Otherwise, every vector, scalar, matrix etc has at least two dimensions in size.

Walter Roberson
Walter Roberson 2012 年 5 月 23 日
You cannot. All arrays in MATLAB show up as 2 or more dimensions for the purposes of size. You can, however, get a column vector.
x = 1 : 10;
size(x)
x1 = x(:);
size(x1)
If you have a row vector, you can use the .' operator to turn it into a column vector:
x = 1 : 10;
size(x)
x1 = x.';
size(x1)
You can construct a column vector directly:
x = (1 : 10).'
size(x)
x = [1; 2; 3; 4; 5];
size(x)

Jan
Jan 2012 年 5 月 24 日
Although Sean and Walter have stated it already, I repeat it again: "Mat"lab has been designed as "Matrix" calculator, therefore all arrays have been matrices at first. After Matlab 4.1 multidimensional arrays have been added, but the matrix like shape of vectors has not been removed due to backward compatibility.

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by