How can I merge vector elements into a single number of type double?
15 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Lazaros Ioakeimidis
il 4 Feb 2019
Commentato: Guillaume
il 5 Feb 2019
Hello,
How can I transform this vector:
v=[1 2 3]
into this scalar of type double?:
k=123
Thank you,
Lazaros.
0 Commenti
Risposta accettata
Più risposte (2)
YT
il 4 Feb 2019
Modificato: YT
il 4 Feb 2019
Something like this?
A = [1 2 3];
joined = str2num(strjoin(num2cell(num2str(A(:))),''));
%>> joined = 123 (type double)
There are probably some more elegant solutions, but this is what I came up with for now.
3 Commenti
Guillaume
il 5 Feb 2019
Indeed but that is most likely the case I assume.
A simpler, yet more generic solution, using number->string->number conversion:
str2num(strjoin(compose('%d', A), ''))
Vedere anche
Categorie
Scopri di più su Logical 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!