Make a vector into a call of a function
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Nikos Karamolegkos
le 13 Avr 2015
Commenté : Nikos Karamolegkos
le 14 Avr 2015
Hi, i would like to use bi2de for some elements of a vector A. If A(1)=0 A(2)=0 A(3)=1 and i call bi2de as bi2de(A(1:3)) i get the dec of each element A(1) A(2) and A(3). I would like to take the dec of bi2de([A(1) A(2) A(3)]). How can i create this vector for random number of elements in [ ] without creating the vector before for example using while-loop. thanks
0 commentaires
Réponse acceptée
Stephen23
le 13 Avr 2015
Modifié(e) : Stephen23
le 14 Avr 2015
According to your definition
A(1)=0 A(2)=0 A(3)=1
then we get
A = [0,0,1]
which means we can simply call
bi2de(A)
Whatever method you use it will have to create a vector (or matrix) before these values are passed to bi2de.
7 commentaires
Stephen23
le 14 Avr 2015
Modifié(e) : Stephen23
le 14 Avr 2015
"-bi2de(A(1)) i will take 0 -bi2de(A(2)) i will take 0 -bi2de(A(3)) i will take 1, that is exactly the same as writing bi2de(A(1:3))"
Except that these are not the same same thing, if A is a row vector. Try it. Your confusion might be happening because you have a column vector for A: is A a column vector? What do you get if you call this?:
size(A)
The vector-orientation is very important, as will be clear when you read the documentation and try some examples:
>> bi2de([0,0,1])
ans =
4
>> bi2de([0;0;1])
ans =
0
0
1
"I want to be give A(1) A(2) A(3) as one bin value the value 001"
Which is exactly how bi2de treats a horizontal vector input, in which case you can use any of my suggested solutions. If your input vector A is a column vector, then the function bi2de will treat each row as a separate value to convert, as the documentation clearly states. You can simply transpose the input vector to turn it into a horizontal vector if you want it considered as one value:
>> A = randi([0,1],12,1)
A =
0
0
1
1
0
0
0
1
1
1
0
1
>> bi2de(A(1:3)) % each row as separate value
ans =
0
0
1
>> bi2de(A(1:3).') % transposed into row vector
ans =
4
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!