concatenate column values in a vector
1 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
KALYAN ACHARJYA
2019-11-20
编辑:KALYAN ACHARJYA
2019-11-20
Simpler way:
v=[1,0,1,0];
result=str2num(sprintf('%1d',v))
Result:
result =
1010
>>
0 个评论
更多回答(2 个)
Erivelton Gualter
2019-11-20
You can use the following line of code:
v2 = sum(v1*diag(10.^(length(v1)-1:-1:0)));
0 个评论
Steven Lord
2019-11-20
Treat v1 as the coefficients of a polynomial and evaluate that polynomial for x = 10.
v1 = [ 1,0,1,0];
v2 = polyval(v1, 10)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!