How can I use the loop 'for' or other, to produce the same matrix (24,72) depicted in the figure? kind regards.

 채택된 답변

Joseph Cheng
Joseph Cheng 2016년 1월 15일
편집: Joseph Cheng 2016년 1월 15일

2 개 추천

since it is a nice simple pattern of (zeros for columns that are a multiple of 3) then:
DesiredResult = ones(24,72);
DesiredResult(:,3:3:end)=0;

추가 답변 (1개)

Brendan Hamm
Brendan Hamm 2016년 1월 15일

1 개 추천

You could do this with a loop:
A = ones(24,72);
for k = 1:72
if rem(k,3) == 0
A(:,k) = 0;
end
end
or you could do this in one line:
A = repmat([1 1 0],24,72/3);
The latter is much faster and more elegant.

댓글 수: 1

ET-TAOUSSI mehdi
ET-TAOUSSI mehdi 2016년 1월 16일
the last is a good solution, thank you Brendan Hamm.

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

카테고리

도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by