how to use a variable defined in one if loop in another loop also in matlab
2 次查看(过去 30 天)
显示 更早的评论
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
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
2023-1-21
The numeric 1 is not equal to the text '1', Lets check right now:
strcmpi(1,'1')
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 Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!