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!