"Attempt to reference field of non-structure array" error message
Mostrar comentarios más antiguos
I have this code to calculate Value-at-Risk with Monte Carlo simulation
function mean_percentile=MCSimulation(num_sim,seed,p,input_file)
database=xlsread(input_file);
[row,col]=size(database);
percentili=zeros(row,seed);
for j=1:seed
for i=1:row
a=normrnd(database(i,1),database(i,2),1,num_sim);
percentili(i,j) = prctile(a(1,:),p);
clear a
end
randn('state',sum(100*clock));
end
mean_percentile=zeros(row,1);
for i=1:row
mean_percentile(i,1)=-mean(percentili(i,:));
end
clear database
end
but then when i try using it I have this error message:
Attempt to reference field of non-structure array.
Can anyone help me please?
thanks very much!
Respuesta aceptada
Más respuestas (2)
Image Analyst
el 7 de Sept. de 2013
0 votos
I don't see any structure in that code. There is no expressions that looks something like structureName.field. You'll need to give the exact error message - all the text in red, don't snip or paraphrase.
4 comentarios
Walter Roberson
el 7 de Sept. de 2013
We might also need to know the MATLAB version.
Turi
el 8 de Sept. de 2013
Image Analyst
el 8 de Sept. de 2013
Editada: Image Analyst
el 8 de Sept. de 2013
It thinks r is a structure, and that xls if a field (member) of the structure called r. Your function expects a filename, which should be a string, 'r.xls', not a structure field r.xls, unless that member is also a filename string. In your case you clearly just forgot to wrap your filename in single quotes to make it a string. So pass in 'r.xls' and it should work, as Walter already pointed out. This clearly illustrates the delay in providing you an answer when you don't give us the full error message but just give us a small snippet of the full error message. You could have had this solved yesterday if you had just given us the full error message.
Turi
el 8 de Sept. de 2013
vahide jafari
el 23 de Feb. de 2015
0 votos
Hi every body I wanna use function som_autolabel(sTo,sFrom,mode,inds) but it gives me this error:Attempt to reference field of non-structure array.
I do not know for what it gives this. please help me i need it.
Best
vahide
1 comentario
Image Analyst
el 23 de Feb. de 2015
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!