Why do I get the error "Undefined function or variable"?
Show older comments
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 Comments
Adam
on 28 Feb 2018
Make sure that c, x, lat, lon and dem are all defined.
Ardi Nur Armanto
on 28 Feb 2018
Walter Roberson
on 28 Feb 2018
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
on 28 Feb 2018
Rik
on 28 Feb 2018
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
on 28 Feb 2018
Adam
on 28 Feb 2018
What exactly are you trying to do here?
fungsi6 = zeros(:,i1);
Guillaume
on 28 Feb 2018
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
on 28 Feb 2018
Ardi Nur Armanto
on 28 Feb 2018
Walter Roberson
on 28 Feb 2018
I doubt that anyone remembers what the .\ operator does so I would not use that without a comment
Guillaume
on 28 Feb 2018
The line in the error message does not appear in the code you've posted. How do you explain that?
Ardi Nur Armanto
on 28 Feb 2018
Answers (1)
Walter Roberson
on 28 Feb 2018
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.
Categories
Find more on Instrument Control Toolbox Supported Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!