"Attempt to reference field of non-structure array" error message
Afficher commentaires plus anciens
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!
Réponse acceptée
Plus de réponses (2)
Image Analyst
le 7 Sep 2013
0 votes
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 commentaires
Walter Roberson
le 7 Sep 2013
We might also need to know the MATLAB version.
Turi
le 8 Sep 2013
Image Analyst
le 8 Sep 2013
Modifié(e) : Image Analyst
le 8 Sep 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
le 8 Sep 2013
vahide jafari
le 23 Fév 2015
0 votes
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 commentaire
Image Analyst
le 23 Fév 2015
Catégories
En savoir plus sur Spreadsheets dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!