필터 지우기
필터 지우기

how velocize it? (vectorize it)

조회 수: 2 (최근 30일)
aldo
aldo 2023년 10월 8일
편집: aldo 2023년 10월 8일
a=magic(8)
a = 8×8
64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1
b=[1 3 2 4 5 5 8 3] % (b is always >0)
b = 1×8
1 3 2 4 5 5 8 3
[~,c]=size(a);
B=a;
for i=1:c
if b(i)>1
B(1:b(i)-1,i)=0;
end
end
B
B = 8×8
64 0 0 0 0 0 0 0 9 0 54 0 0 0 0 0 17 47 46 0 0 0 0 24 40 26 27 37 0 0 0 33 32 34 35 29 28 38 0 25 41 23 22 44 45 19 0 48 49 15 14 52 53 11 0 56 8 58 59 5 4 62 63 1

채택된 답변

Bruno Luong
Bruno Luong 2023년 10월 8일
a=magic(8)
a = 8×8
64 2 3 61 60 6 7 57 9 55 54 12 13 51 50 16 17 47 46 20 21 43 42 24 40 26 27 37 36 30 31 33 32 34 35 29 28 38 39 25 41 23 22 44 45 19 18 48 49 15 14 52 53 11 10 56 8 58 59 5 4 62 63 1
b=[1 3 2 4 5 5 8 3] % (b is always >0)
b = 1×8
1 3 2 4 5 5 8 3
B = a.* ((1:size(a,1))' >= b)
B = 8×8
64 0 0 0 0 0 0 0 9 0 54 0 0 0 0 0 17 47 46 0 0 0 0 24 40 26 27 37 0 0 0 33 32 34 35 29 28 38 0 25 41 23 22 44 45 19 0 48 49 15 14 52 53 11 0 56 8 58 59 5 4 62 63 1
  댓글 수: 1
aldo
aldo 2023년 10월 8일
편집: aldo 2023년 10월 8일
thank you.!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Robust Control Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by