undefined function type double
1 view (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Sajid Khan
on 6 Feb 2014
it you don't have anything in vettore, then how can you perform the step vettore(i)=vettore(i)+1;
More Answers (2)
Walter Roberson
on 5 Feb 2014
The files are all empty, or the first line of each file begins with something that is not understandable as a number.
3 Comments
Walter Roberson
on 5 Feb 2014
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
on 6 Feb 2014
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 Comments
Walter Roberson
on 6 Feb 2014
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.
See Also
Categories
Find more on File Operations 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!