フィルターのクリア

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 Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by