How to "concatenate" an array by merging the elements?

9 ビュー (過去 30 日間)
Alex Chen
Alex Chen 2018 年 10 月 5 日
回答済み: madhan ravi 2018 年 10 月 5 日
Let's say that I have an array
x = [3,0,0]
Is it possible to somehow manipulate this so that I can output a result of y=300? I am wondering if I can "concatenate" this array such that it outputs a combination of the entire row as a single element or numerical value. So for example if I had
x = [1,0,0 ; 2,0,0 ; 3,0,0]
I would want something that would allow me to output
ans = [100 ; 200 ; 300]
Any help and suggestions are appreciated.

回答 (2 件)

KSSV
KSSV 2018 年 10 月 5 日
x = [1,0,0 ; 2,0,0 ; 3,0,0] ;
N = [100 10 1] ;
p = sum(x.*N,2)

madhan ravi
madhan ravi 2018 年 10 月 5 日
x = [1,0,0 ; 2,0,0 ; 3,0,0]
x1 = x(1,:)
x2 = x(2,:)
x3 = x(3,:)
x1=str2num(strcat(num2str(x1(1)),num2str(x1(2)),num2str(x1(3))))
x2=str2num(strcat(num2str(x2(1)),num2str(x2(2)),num2str(x2(3))))
x3=str2num(strcat(num2str(x3(1)),num2str(x3(2)),num2str(x3(3))))
X=[x1;x2;x3]
Would work for any numbers

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by