필터 지우기
필터 지우기

undefined function type double

조회 수: 3 (최근 30일)
Nicola
Nicola 2014년 2월 5일
댓글: Nicola 2014년 2월 6일
Good evening friends,
i have a very simple problem with this code(but my brain is out of service and i need to solve it by tomorrow)
arr=1;
deltaTe=0.5;
deltaTemax=80;
imax=100;
for giorno=1:365
nname=['Tuttigiorni/Variazionegiorno_',num2str(giorno),'.txt'];
nfid=fopen(nname,'r');
while ~feof(nfid)
hhead=fscanf(nfid,'%f',2);
if ~isempty(hhead)
gggradi(arr)=hhead(2);
ggradi(arr)=fix(gggradi(arr));
i=fix(ggradi(arr)/deltaTe)+1;
vettore(i)=vettore(i)+1;
end
arr=arr+1;
end
end
vettore
Error: Undefined function 'vettore' for input arguments of type 'double'. I want to save i value in the vettore array Thanks so much

채택된 답변

Sajid Khan
Sajid Khan 2014년 2월 6일
it you don't have anything in vettore, then how can you perform the step vettore(i)=vettore(i)+1;
  댓글 수: 1
Nicola
Nicola 2014년 2월 6일
Thanks man! Yesteray my brain was out of service ;)

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

추가 답변 (2개)

Walter Roberson
Walter Roberson 2014년 2월 5일
The files are all empty, or the first line of each file begins with something that is not understandable as a number.
  댓글 수: 3
Walter Roberson
Walter Roberson 2014년 2월 5일
Ah you did not include the traceback of messages so I thought the message was referring to the vettore at the end of the program, which indeed would not exist in the circumstances I mention.
You are starting off with vettoree completely undefined. Then you are trying to calculate vettore(43)+1 and assign that value somewhere. But the vector does not exist, so it is going to complain. It does not create the location to be assigned to until after it has evaluated the right-hand side. So preallocate.
Note: you are not putting "i" into the location, you are adding 1 (the digit) to the location, so you are counting the occurrences.
Nicola
Nicola 2014년 2월 6일
Thanks!

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


Image Analyst
Image Analyst 2014년 2월 6일
I think it's never getting into the while loop to set vettore because it can't open the file. Here, put this code in right before you call fopen():
% Read in the file.
folder = ''Tuttigiorni';
baseFileName = sprintf('Variazionegiorno_%d.txt', giorno;
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
% Check if file exists.
if ~exist(fullFileName, 'file')
% File doesn't exist -- didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist in the search path folders.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
Then call fopen:
nfid = fopen(fullFileName ,'r');
  댓글 수: 2
Walter Roberson
Walter Roberson 2014년 2월 6일
If it had been unable to open the file then the feof() would have error'd out in an obvious manner before it tried to use the variable.
Nicola
Nicola 2014년 2월 6일
Thanks! It opened the file, the problem was that i didn't initialize the array vettore!

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

카테고리

Help CenterFile Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by