Is it possible to concatenate two numeric arrays such that the corresponding numbers in each matrix are now represented as a new number in MATLAB ?

3 ビュー (過去 30 日間)
I would like to concatenate two matrices A and B into a new matrix C as illustrated in the description below:
A = [1 2 3]
B = [4 5 6]
New matrix C should be:
C = [14 25 36]

採用された回答

MathWorks Support Team
MathWorks Support Team 2011 年 6 月 13 日
There is no direct function in MATLAB that can accomplish concatenating two numbers from an array in two matrices (index wise). The idea to concatenate two numbers per index from two matrices such that a resultant matrix has concatenated numbers is as follows:
a1 = [1 2 3]';
a2 = [4 5 6]';
% Convert both the numbers to strings
b1 = num2str(a1);
b2 = num2str(a2);
% Concatenate the two strings element wise
c1 = strcat(b1, b2);
% Convert the result back to a numeric matrix
result = str2num(c1);
Please note that concatenating two numbers based on their index is not supported as a basic programming feature.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

タグ

タグが未入力です。

製品


リリース

R2011a

Community Treasure Hunt

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

Start Hunting!

Translated by