필터 지우기
필터 지우기

how to use a variable defined in one if loop in another loop also in matlab

조회 수: 1 (최근 30일)
Imaad Aslam
Imaad Aslam 2023년 1월 21일
댓글: Stephen23 2023년 1월 21일
if strcmpi(end_condt, '1')
D = l/10;
depth = D - clr_cover - 5;
end
suprt_condtn = input('Is the Span (1) C/C Distance or (2)Clear Span = ');
suprt_lngth = input('What is the length of suport (in mm) ; ');
if strcmpi(suprt_condtn, '1')
eff_span = min(l , ((l - suprt_lngth) + depth));
elseif strcmpi(suprt_condtn, '2')
eff_span = min((l + suprt_lngth) , (l + depth));
else
isempty(suprt_condtn)
eff_span = min(l , ((l - suprt_lngth) + depth));
end
Here it says "Undefined function or variable 'depth'"
  댓글 수: 2
Vilém Frynta
Vilém Frynta 2023년 1월 21일
It would be helpful to see the rest of your code. It appears to me that you have depth defined inside a if statement, where your conditions might not be met. It might be possible that your variable called end_condt is not a string (but a double or else), which would lead to logical 0.
Stephen23
Stephen23 2023년 1월 21일
The numeric 1 is not equal to the text '1', Lets check right now:
strcmpi(1,'1')
ans = logical
0
Yet your code is written on the assumption that is true. But in fact, MATLAB does not implicitly convert text to the numeric values that it might happen to contain. Or not.
Solution: store numeric values as numeric. And then compare them as numeric.

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

답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by