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!