How can one define this vector in an elegant way?
Afficher commentaires plus anciens
I have
x=0:0.01:1
then I want to create a vector y that corresponds to each value of x
ngrid=((1-0)/0.01)1;
y=zeros(ngrid,1);
What will be a compact way to define y?
7 commentaires
madhan ravi
le 2 Juin 2020
Could you be more explanatory?
David Hill
le 2 Juin 2020
I don't understand what you are asking. ngrid does not make sense. What do you want y to be (provide and example).
alpedhuez
le 2 Juin 2020
Walter Roberson
le 2 Juin 2020
y=zeros(size(x)) ;
alpedhuez
le 2 Juin 2020
darova
le 14 Juin 2020
y = x*0;
Suraj Sudheer Menon
le 14 Juin 2020
An approach could be to perform elementwise multiplication and perform transpose operation to obtain the a column vector.
y=(x.*0)' ;
Réponse acceptée
Plus de réponses (1)
Suraj Sudheer Menon
le 14 Juin 2020
0 votes
An approach could be to perform elementwise multiplication and perform transpose operation to obtain the a column vector.If a row vector of the same characteristics are needed the transpose operation can be avoided.
y=(x.*0)' ; (column vector);
y=(x.*0) ; (row vector)
3 commentaires
alpedhuez
le 18 Juin 2020
madhan ravi
le 18 Juin 2020
*
Walter Roberson
le 18 Juin 2020
.* is element-by-element multiplication. x.*0 is an all-zero array the same size as x. (x.*0)' is the conjugate transpose of that all-zero array, and since 0 is real, that is the same as the plain transpose of the all-zero array. When x is a row vector, the all-zero array would be a row vector and the transpose of it would be a column vector of zeros with the same number of elements as x had.
Catégories
En savoir plus sur Logical dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!