What is the meaning of this simple 1 line matlab code?

22 ビュー (過去 30 日間)
minsoo kim
minsoo kim 2018 年 4 月 3 日
回答済み: Alok Nimrani 2018 年 4 月 6 日
X = [x, zeros(1,n)];
x is a 1xN matrix.

回答 (1 件)

Alok Nimrani
Alok Nimrani 2018 年 4 月 6 日
Hi Minsoo Kim,
zeros(1,n) creates a 1xn vector of zeros i.e.
>> zeros(1,5)
ans =
0 0 0 0 0
You can read more about ‘zeros’ at the following link: https://www.mathworks.com/help/matlab/ref/zeros.html
Now, ‘x’ is a 1xn vector and the operation being performed is:
>> X = [x zeros(1,n)];
Here, ‘[ ]’ is the matrix constructor operator and when the elements within the brackets are separated by space, the resulting matrix is a row-wise concatenation of the elements. So, the above operation is basically a row-wise concatenation of ‘x’ and ‘zeros(1,n)’. Check the following code as an example:
>> x = ones(1,5)
x =
1 1 1 1 1
>> X = [x zeros(1,5)]
X =
1 1 1 1 1 0 0 0 0 0
For more information about the matrix constructor operator '[ ]', you can check the following link: https://www.mathworks.com/help/matlab/math/creating-and-concatenating-matrices.html#f1-84906
Hope this clears your query.
Thanks.

カテゴリ

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!