problem with undefined function or variable

i have this problem i don't know if matlab going mad :
Undefined function or variable 'name of function'
for the first time it works perfectly but after i close matlab and re-open it ,it gives that error.
can you help me with that
thank you

1 件のコメント

Stephen23
Stephen23 2017 年 5 月 13 日
@best16 programmer: please edit your question and show us the complete error message. This means all of the red text.

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

回答 (1 件)

Star Strider
Star Strider 2017 年 5 月 13 日

0 投票

Without seeing your code, it is not possible to determine the problem. If 'name of function' is a variable (character array), there should be no problem.
Example:
x = 'name of function';
What are you doing with it?

8 件のコメント

best16 programmer
best16 programmer 2017 年 5 月 13 日
'name of function' is a column
Star Strider
Star Strider 2017 年 5 月 13 日
If it is a variable name, it must not have any spaces in its name.
Use: name_of_function for the variable name instead.
I have no explanation for its working the first time and not after. I might if I could see the relevant parts of your code, and the complete (all the red text copied from your Command Window) error message and pasted to a Comment here.
Otherwise, I am simply guessing as to what the problem actually is. In my experience, that is an extremely inefficient troubleshooting method.
best16 programmer
best16 programmer 2017 年 5 月 13 日
編集済み: best16 programmer 2017 年 5 月 13 日
j=1:34;
r=d(24:501,:,j);
e=min(min(d(24:501,:,j)));
if((min(r)<=e*0.4))
Location = find(r == min(r))
YValue(j) = time(Location)
value=YValue'
peak=(value-0.0004)*10^(3)
end
plot(Vs(10:size(peak)-4),peak(10:size(peak)-4),'*b')
here is the error:
Undefined function or variable 'peak'.
Stephen23
Stephen23 2017 年 5 月 13 日
@best16 programmer: please give the complete error message.
Star Strider
Star Strider 2017 年 5 月 13 日
It is difficult to understand your code.
It appears to depend on the if condition, since the assignments inside the if block will not execute if (min(r) > e*0.4), leaving them all undefined and ‘empty’. Since ‘peak’ is assigned in that if block, if the if condition is not satisfied, none of the values in the if block will be assigned.
Assign ‘peak’ to be NaN or some appropriate scalar value before the if block. (It will be replaced with the correct value if the if condition is satisfied and the if block executes.) That will avoid the error that you are currently getting.
I cannot determine if it will avoid problems in the rest of your code.
best16 programmer
best16 programmer 2017 年 5 月 13 日
i forgot to add it
Error in new_test_time2peak (line 94) plot(Vs(10:size(peak)-4),peak(10:size(peak)-4),'*b')
best16 programmer
best16 programmer 2017 年 5 月 13 日
thanks for the answers,but that same code works for the first time
Star Strider
Star Strider 2017 年 5 月 13 日
I cannot determine what ‘peak’ is with respect to length:
YValue(j) = time(Location)
value=YValue'
The problem is that it will return a (1x2) vector for the result of the size call.
So:
peak = 1:42;
v = 10:size(peak)-4
v =
1×0 empty double row vector
That will not work, since plot expects vector arguments, and ‘empty’ vectors do not fulfill that requirement.

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

カテゴリ

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

製品

質問済み:

2017 年 5 月 13 日

コメント済み:

2017 年 5 月 13 日

Community Treasure Hunt

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

Start Hunting!

Translated by