필터 지우기
필터 지우기

How to create multiple matrices with multiple variable?

조회 수: 1 (최근 30일)
Hao Ming Low
Hao Ming Low 2022년 1월 21일
답변: Chunru 2022년 1월 21일
provided x=1:100
How to create 100 matrices (all must be having pattern of [x 0 0; 0 x 0; 0 0 x]) at the same time without typing it one by one?
P.S. : I meet this problem when studying multiple variable linear regression

답변 (1개)

Chunru
Chunru 2022년 1월 21일
n = 5; % 100
% each slice of a is a matrix you want to produce:
a = eye(3).*reshape(1:n, [1 1 n])
a =
a(:,:,1) = 1 0 0 0 1 0 0 0 1 a(:,:,2) = 2 0 0 0 2 0 0 0 2 a(:,:,3) = 3 0 0 0 3 0 0 0 3 a(:,:,4) = 4 0 0 0 4 0 0 0 4 a(:,:,5) = 5 0 0 0 5 0 0 0 5

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by