How can I create a matrix with matrix elements of different datatypes?

11 ビュー (過去 30 日間)
C A
C A 2021 年 11 月 16 日
回答済み: Dave B 2021 年 11 月 16 日
I want to make a nx2 matrix in which the first column consists of integers but the second column consists of a structure. Something like this,
Please let me know how to create this matix. Thanks in advance!

回答 (1 件)

Dave B
Dave B 2021 年 11 月 16 日
You can use a cell array to mix datatypes:
n=5;
mat = cell(n,2);
for i = 1:n
mat{i,1} = i;
mat{i,2} = -i:i;
end
mat
mat = 5×2 cell array
{[1]} {[ -1 0 1]} {[2]} {[ -2 -1 0 1 2]} {[3]} {[ -3 -2 -1 0 1 2 3]} {[4]} {[ -4 -3 -2 -1 0 1 2 3 4]} {[5]} {[-5 -4 -3 -2 -1 0 1 2 3 4 5]}

カテゴリ

Help Center および File ExchangeNumerical Integration and Differentiation についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by