필터 지우기
필터 지우기

Create a vector that only the first element and the last element is 0

조회 수: 3 (최근 30일)
Ming Ki Lee
Ming Ki Lee 2017년 1월 25일
편집: per isakson 2017년 1월 25일
B=zeros(mx,1);
for z=1:mx
if B(z,1) == B(1,1)
B(z,1) = 0;
elseif B(z,1) == B(mx,1)
B(z,1) = 0;
else
B(z,1) = 1;
end
end
I want to create a vector B that only (1,1) and (mx,1) equal to 0 but from (2 to mx,1) equal to 1. But my code still only show a zero matrix. How can I fix that?

답변 (1개)

KSSV
KSSV 2017년 1월 25일
편집: KSSV 2017년 1월 25일
N = 10 ; % length of the vector
iwant = ones(N,1) ;
iwant(1) = 0 ;
iwant(N) = 0 ;
  댓글 수: 2
Jan
Jan 2017년 1월 25일
편집: Jan 2017년 1월 25일
Or with the loop:
B = zeros(mx,1);
for z = 2:mx-1
B(z) = 1;
end
This is not efficient and I would not use it in real programs, but it shows how your loop can be modified.

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by