フィルターのクリア

construct a vector formed by arrays of different lengths

1 回表示 (過去 30 日間)
EldaEbrithil
EldaEbrithil 2020 年 9 月 2 日
コメント済み: KSSV 2020 年 9 月 2 日
Hi all
i want to built a vector using multiple arrays with different length. First of all with thi code
a=zeros(100000,sum(c));
for i=1:3
a(i,:)=b(i)*ones(1,c(i));
end
with this code i want to built a 3xsum( c) matrix. b has the same dimension of c but c has different lengths!! So when multiplied with b give different lengths of a. I want to join neatly the three vector a obtained; how can i do that?
Thank you for the help!!
Regards
  3 件のコメント
KSSV
KSSV 2020 年 9 月 2 日
what is c? in a there are 3 rows, but you initiated it with 100000 rows.
EldaEbrithil
EldaEbrithil 2020 年 9 月 2 日
b is an array with 3 components
c is an array with 3 component which has value:[101,17,1]
i want to obatin
a1=b1-1,b1-2,b1-3,b1-4,.....b1-101
a2=b2-1,b2-2,b2-3,b2-4,.....b2-17
a3=b3-1
and then obtain a=[a1,a2,a3]

サインインしてコメントする。

採用された回答

KSSV
KSSV 2020 年 9 月 2 日
a=cell(3,1);
for i=1:3
a{i}=b(i)*ones(1,c(i));
end
  4 件のコメント
EldaEbrithil
EldaEbrithil 2020 年 9 月 2 日
編集済み: EldaEbrithil 2020 年 9 月 2 日
Ok solved with this
Acell=vertcat(a{:});
KSSV
KSSV 2020 年 9 月 2 日
yes use vertcat or cell2mat.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by