フィルターのクリア

Use vector to create 3rd dimension at each point in a matrix

5 ビュー (過去 30 日間)
Mahmood Haddara
Mahmood Haddara 2023 年 1 月 19 日
コメント済み: Mahmood Haddara 2023 年 1 月 19 日
I have an N-by-N matrix and a vector of length M. I want to create a 3-D array where at each point in the matrix, the third dimension is my vector.
This is the code I have, but I would like to know if there is a faster way that I can do this (probably without a loop). Any ideas?
N=10;
vec=1:5;
for i=1:N
for j=1:N
array(:,i,j)=vec;
end
end

採用された回答

KSSV
KSSV 2023 年 1 月 19 日
N = 10 ;
vec = 1:5 ;
b = repmat(vec',1,N,N) ;

その他の回答 (0 件)

カテゴリ

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

タグ

製品


リリース

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by