Effacer les filtres
Effacer les filtres

Converting 1*4 array into 1*1

3 vues (au cours des 30 derniers jours)
Tallha Akram
Tallha Akram le 4 Fév 2013
hi,
I have an array a=[1 2 3 4] with dimension 1*4 and i want it to convert into
value 1234 of size 1*1 double.
other example : a=[4 5 6 7 8 9] size 1*6 , convert into 456789 , size 1*1 double.

Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 4 Fév 2013
Modifié(e) : Azzi Abdelmalek le 4 Fév 2013
a=[1 2 3 4];
b=num2str(a);
b(b==' ')=[];
out=str2num(b)

Plus de réponses (3)

Wayne King
Wayne King le 4 Fév 2013
There are many ways. One way
a = [1 2 3 4];
b = num2str(b);
b(isspace(b)==1) = [];
a = str2num(b);

Muge Erinc
Muge Erinc le 4 Fév 2013
Modifié(e) : Azzi Abdelmalek le 4 Fév 2013
Might this work?
a=[1 2 3 4] ;
b='';
for i=1:size(a,2)
b=[b num2str(a(i))];
end
str2double(char(b))

Jos (10584)
Jos (10584) le 4 Fév 2013
Avoid the overhead of converting numbers into strings and back ... Use simple school math and a matrix multiplication:
a = [2 3 0 1 5]
b = 10.^(numel(a)-1:-1:0) * a(:)

Catégories

En savoir plus sur Data Type Conversion dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by