Borrar filtros
Borrar filtros

undefined function type double

3 visualizaciones (últimos 30 días)
Nicola
Nicola el 5 de Feb. de 2014
Comentada: Nicola el 6 de Feb. de 2014
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

Respuesta aceptada

Sajid Khan
Sajid Khan el 6 de Feb. de 2014
it you don't have anything in vettore, then how can you perform the step vettore(i)=vettore(i)+1;
  1 comentario
Nicola
Nicola el 6 de Feb. de 2014
Thanks man! Yesteray my brain was out of service ;)

Iniciar sesión para comentar.

Más respuestas (2)

Walter Roberson
Walter Roberson el 5 de Feb. de 2014
The files are all empty, or the first line of each file begins with something that is not understandable as a number.
  3 comentarios
Walter Roberson
Walter Roberson el 5 de Feb. de 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.
Nicola
Nicola el 6 de Feb. de 2014
Thanks!

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 6 de Feb. de 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 comentarios
Walter Roberson
Walter Roberson el 6 de Feb. de 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.
Nicola
Nicola el 6 de Feb. de 2014
Thanks! It opened the file, the problem was that i didn't initialize the array vettore!

Iniciar sesión para comentar.

Categorías

Más información sobre Data Import and Analysis en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by