how to use a variable defined in one if loop in another loop also in matlab
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Vilém Frynta
le 21 Jan 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
le 21 Jan 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.
Réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!