Effacer les filtres
Effacer les filtres

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

2 vues (au cours des 30 derniers jours)
minsoo kim
minsoo kim le 3 Avr 2018
X = [x, zeros(1,n)];
x is a 1xN matrix.

Réponses (1)

Alok Nimrani
Alok Nimrani le 6 Avr 2018
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.

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!