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

38 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

Community Treasure Hunt

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

Start Hunting!