Why do I get the error "Undefined function or variable"?
显示 更早的评论
I am receiving the following error message, how can I resolve this issue?
fungsi6 = zeros(:,i1);
for i1=1:c
fungsi6(:,i1)=c(1,i1) + c(2,i1)*x(i1,:)' + c(3,i1)*lat' + c(4,i1)*lon' + c(5,i1)*dem'
end
13 个评论
Adam
2018-2-28
Make sure that c, x, lat, lon and dem are all defined.
Ardi Nur Armanto
2018-2-28
Walter Roberson
2018-2-28
It is not recommended to try to name a variable "zeros" as that is the name of of an important function to allocate memory that is initialized to 0. In its function form you would never pass a : to it.
Ardi Nur Armanto
2018-2-28
Rik
2018-2-28
Rename the variable zeros. The problem is not with this loop, but with how you are trying to define fungsi6. If you show us the 18 lines before this, we might be able to give more specific advice.
Ardi Nur Armanto
2018-2-28
Adam
2018-2-28
What exactly are you trying to do here?
fungsi6 = zeros(:,i1);
Guillaume
2018-2-28
This is a different code from the one in your original question. So we have absolutely no idea which line or which code is causing the error.
Therefore, please confirm the exact code you are using and give us the entire error message without any modification. Just copy and paste everything in red.
Ardi Nur Armanto
2018-2-28
Ardi Nur Armanto
2018-2-28
Walter Roberson
2018-2-28
I doubt that anyone remembers what the .\ operator does so I would not use that without a comment
Guillaume
2018-2-28
The line in the error message does not appear in the code you've posted. How do you explain that?
Ardi Nur Armanto
2018-2-28
回答(1 个)
Walter Roberson
2018-2-28
When you use an array as the end point of a : operator the first element of the array is extracted and the rest are ignored. Your
for i1=1:c
Is the same as
for i1=1:c(1,1)
This would not execute even once if c(1,1) was not at least 1, and since you do not initialize the variable assigned to in the loop that would leave the variable undefined.
I see no reason to expect that c(1,1) should be at least 1.
类别
在 帮助中心 和 File Exchange 中查找有关 Instrument Control Toolbox Supported Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!