What are possible issues if MATLAB doesn't recognise a variable?

if strcmp(str(1:3), 'Min') == 1
VZ = 1;
end
if strcmp(str(1:3), 'Max') == 1
VZ = -1;
end
VZ
[k l s] = evIII_weibull('param', mevI, sevI, x0, VZ);
VZ
Good afternoon,
the first time I call "VZ" MATLAB gives me the correct value, but after giving it as input for another function MATLAB doens't know the value anymore. Does anyone know how this is possible? Furthermore the function "evIII_weibull" doesn't accept VZ as input (eventhough I have declared it as input in evIII_weibull.m
This is the error message I get:
??? Input argument "VZ" is undefined.
Please help

8 件のコメント

madhan ravi
madhan ravi 2019 年 1 月 29 日
The possible reason is that if it doesn't satisfy the if conditions, we may need to see what str contains to narrow it down.
if strcmp(str(1:3), 'Min') == 1
VZ = 1;
elseif strcmp(str(1:3), 'Max') == 1
%^^^^------ should be inside the if statement
VZ = -1;
end
beginner94
beginner94 2019 年 1 月 29 日
The str is "Max_deltaTMy_3T" and immediately after the condition VZ is still recognised. It is only after giving it to evIII_weibull as input that MATLAB isn't able anymore to give back the value
madhan ravi
madhan ravi 2019 年 1 月 29 日
Change " " to single quotes ' ' and try again.
beginner94
beginner94 2019 年 1 月 29 日
I found the issue, it was a missing input in the evIII_weibull!
Thank you for your help @madhan ravi!
madhan ravi
madhan ravi 2019 年 1 月 29 日
編集済み: madhan ravi 2019 年 1 月 29 日
Which was missing ?
[k l s] = evIII_weibull('param', mevI, sevI, x0, VZ);
% ^^^---- was there already
Stephen23
Stephen23 2019 年 1 月 29 日
編集済み: Stephen23 2019 年 1 月 29 日
Possibly the problem was that neither of those strcmp conditions was fulfilled, and thus VZ simply remained undefined. In any case, simpler code for those conditions:
if strncmpi(str,'min',3)
VZ = +1;
elseif strncmpi(str,'max',3)
VZ = -1;
end
OR using switch:
switch lower(str(1:3))
case 'min'
VZ = +1;
case 'max'
VZ = -1;
end
end
beginner94
beginner94 2019 年 1 月 29 日
@madhan ravi
Before VZ was missing an input (required, the function is not varargin)
@Stephen Cobeldick
The if condition is working fine, thank you nevertheless!
beginner94
beginner94 2019 年 1 月 29 日
@Stephen Cobeldick
If I had been aware that the problem was in evIII_weibull I would of course have provided it. Mercy on beginners :)

サインインしてコメントする。

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

製品

リリース

R2007b

質問済み:

2019 年 1 月 29 日

コメント済み:

2019 年 1 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by