Why am i getting length(x) as 11 instead of 16?
조회 수: 1 (최근 30일)
이전 댓글 표시
n=0:15;
답변 (2개)
Image Analyst
2022년 3월 13일
What did you define for x? All we see are definitions for n and x1:
n=0:15;
% Compute x1
x1 = 1 .* (n >= 1) & (n <= 10)
x1Length = length(x1) % Display it's length.
% Now define some x - a different variable than x1
x = [1,2,3,4] % Or whatever it might be.
xLength = length(x) % Display it's length.
I bet you had an x hanging around from a prior run and didn't call "clear all" so when you did length(x) you were getting some x that was still in the base workspace even though it was not in your script. Calling clear all would clear all old variables and prevent a problem like that.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!