matrix and binary bits
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a matrix that I use it like an index, for example: A=[1 3 2 4 1 3] which points to a matrix which represents binary bits B=[00 01 11 10]. How can I produce these bits (like decimal numbers of course) but in a single line matrix (e.g. 0 0 1 1 0 1 1 0 0 0 1 1)? I mean I want: C=B(1) gives me 0 0, C=B(2) gives me 0 1 and so on...
Thank you..
0 Commenti
Risposta accettata
Walter Roberson
il 13 Nov 2011
It is not possible to do what you want. There is no data type in MATLAB with which you can supply a single index and get out a vector of numeric values using () subscripting. Cell arrays come close, but when you use () subscripting with them, you get out a cell array that contains the vector, rather than the vector itself. You can use {} subscripting with a cell array to "unwrap" the cell array from the vector:
B={{0 0} {0 1} {1 1} {1 0}};
C = B{1};
But really it is easier to use straight arrays and appropriate indexing:
B = [0 0; 0 1; 1 1; 1 0];
C = B[1,:];
Più risposte (2)
Fangjun Jiang
il 13 Nov 2011
B=[00 01 11 10];
C=num2str(B','%02d');
or
i=1;
C=sprintf('%02d',B(i));
2 Commenti
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!