ベクトルを補間したい

2 次查看(过去 30 天)
Osamu Goto
Osamu Goto 2022-8-26
例えば、
X=[3 5 1]
を、次のように3倍に増やしたい
Y=[3 3 3 5 5 5 1 1 1]
これを、任意のXについて、任意の倍率で行う演算を、素早く実施したく、教えて下さい。
for文を多用すれば、できることは、わかっています。
  1 个评论
Osamu Goto
Osamu Goto 2022-8-26
自問自答になりましたが、以下で出来ることを理解しました。
Y=[X;X;X];
reshape(Y,1,9)

请先登录,再进行评论。

回答(3 个)

Shunichi Kusano
Shunichi Kusano 2022-8-26
実はrepelemという関数がありまして、それだと1行でできます。

Genki Uebayashi
Genki Uebayashi 2022-8-26
repmatで3行に増やして、reshapeで1行numel列に並び替えでできます。

Hernia Baby
Hernia Baby 2022-8-26
repmatrepelem がコピーを増やすものになります。
要素のみを増やす場合は前者、行列として増やす場合は後者をお使いください。
X=[3 5 1];
repelem(X,3)
ans = 1×9
3 3 3 5 5 5 1 1 1
repmat(X,3)
ans = 3×9
3 5 1 3 5 1 3 5 1 3 5 1 3 5 1 3 5 1 3 5 1 3 5 1 3 5 1
今回はrepelemがやりたいことに該当します。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2012b

Community Treasure Hunt

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

Start Hunting!