Error using variable in a function with trial version

Hello,
I have a problem using my function Selection Sept. It told me that i use date as a function or a command but i don't know where. Why can't I name it in my script, use it in my function and then use it in my script again ? It worked on my friend computer who don't have the trial version but i do and on mine in doesn't work...
Thank you very much

댓글 수: 1

Script :
A = CR1000LaL ;
A(:,2:26) = [];
A(1:4,:) = [];
date = A(:,1)
[A] = SelectionSept (A)
abe = A(1,:);
for l = length(date):-1:1;
for k = 2:length(abe);
while A{l,k} <= 2 || A{l,k} > 3 ;
date(l) = [];
A(l,:) = [];
end
end
end
Function
function [matrice] = SelectionSept (matrice)
for i = length(date):-1:1;
j= date{i};
token = strtok(j{1}(7));
if token ~= '9';
date(i)= [];
matrice(i,:) = [];
end
end
end
Error message : "date" previously appeared to be used as a function or command, conflicting with its use here as the name of a variable. A possible cause of this error is that you forgot to initialize the variable, or you have initialized it implicitly using load or eval.

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2017년 5월 13일
편집: Stephen23 2017년 5월 13일
You should avoid using the variable name date, because this is the name of an inbuilt function date. You should always check if a name is used by calling this: which name_of_function.
The error is simply that you do not pass any date as an argument to your function. If date is not passed (or otherwise explicitly put into that function workspace) then it does not exist in that workspace. In MATLAB function workspaces do not automagically inherit all values from the calling or "higher" workspace: you have to pass them explicitly:
function [matrice] = SelectionSept(matrice,date)

추가 답변 (1개)

dpb
dpb 2017년 5월 13일
function [matrice] = SelectionSept (matrice)
for i = length(date):-1:1;
...
date isn't defined in your function excepting as the builtin Matlab function
>> which date
C:\ML_R2014b\toolbox\matlab\timefun\date.m
because functions have their own context and the array date you created in the script isn't passed to the function.
It would behoove you to not use builtin function names in general; confusion reigns when alias something this way.
While I do NOT recommend it; the code above would function if the sundtion were defined to use date as the argument; then it would become associated with the A array passed internally. BUT, do NOT do this; use some other variable name other than DATE!!!

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

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