how to use a variable defined in one if loop in another loop also in matlab
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Vilém Frynta
el 21 de En. de 2023
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
el 21 de En. de 2023
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.
Respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!