Cases function: why do I get this message "array indices must be positive integers or logical values"
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
Hey,
I want to wrtie the following function in matlab:
I get this message
"array indices must be positive integers or logical values"
It says there is a problem with the line:
else x1(t) = 0;
My code, if someone can help me to fix this :)
t = linspace (-5, 5, 1001);
if (abs(t) <= 1)
x1(t) = 1 - abs(t);
else x1(t) = 0;
end
댓글 수: 0
답변 (1개)
KSSV
2020년 11월 1일
You should use logical indexing. Try something like this:
t = linspace (-5, 5, 1001);
x1 = zeros(size(t)) ;
x1(abs(t)<=1) = 1 - t(abs(t)<=1);
plot(t,x1)
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!