concatenate column values in a vector

1 visualización (últimos 30 días)
Elysi Cochin
Elysi Cochin el 20 de Nov. de 2019
Respondida: Steven Lord el 20 de Nov. de 2019
i have a vector
v1 = [ 1,0,1,0] (dim 1x4 double)
i wanted to join the values in v1 to a new variable
v2 = [1010] (dim 1x1 double)
how to do so

Respuesta aceptada

KALYAN ACHARJYA
KALYAN ACHARJYA el 20 de Nov. de 2019
Editada: KALYAN ACHARJYA el 20 de Nov. de 2019
Simpler way:
v=[1,0,1,0];
result=str2num(sprintf('%1d',v))
here the same question Credit: @per isakson
Result:
result =
1010
>>

Más respuestas (2)

Erivelton Gualter
Erivelton Gualter el 20 de Nov. de 2019
You can use the following line of code:
v2 = sum(v1*diag(10.^(length(v1)-1:-1:0)));

Steven Lord
Steven Lord el 20 de Nov. de 2019
Treat v1 as the coefficients of a polynomial and evaluate that polynomial for x = 10.
v1 = [ 1,0,1,0];
v2 = polyval(v1, 10)

Categorías

Más información sobre Polynomials en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by