undefined function type double

3 次查看(过去 30 天)
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;

更多回答(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.

请先登录,再进行评论。


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