Combining elements in an array
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
sushma sharma
am 12 Jul. 2016
Beantwortet: Star Strider
am 12 Jul. 2016
Hi, I have a logical array, A = [1 0 1]. How can I combine the elements horizontally, so that I have B = [101]? Any help would be appreciated! SS
0 Kommentare
Akzeptierte Antwort
Star Strider
am 12 Jul. 2016
To turn your logical array into a double array, any mathematical operation on it will do the conversion. Here I used ‘+’:
A = logical([1 0 1])
An = +A
whos A*
A =
1 0 1
An =
1 0 1
Name Size Bytes Class Attributes
A 1x3 3 logical
An 1x3 24 double
0 Kommentare
Weitere Antworten (1)
James Tursa
am 12 Jul. 2016
Bearbeitet: James Tursa
am 12 Jul. 2016
Assuming you intend to combine the individual digits into a single decimal number:
B = sum(A.*(10.^(numel(A)-1:-1:0)));
If you intended to make a string instead, then
B = char(A+'0');
0 Kommentare
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!