필터 지우기
필터 지우기

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

조회 수: 2 (최근 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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by