"Attempt to reference field of non-structure array" error message
Ältere Kommentare anzeigen
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!
Akzeptierte Antwort
Weitere Antworten (2)
Image Analyst
am 7 Sep. 2013
0 Stimmen
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 Kommentare
Walter Roberson
am 7 Sep. 2013
We might also need to know the MATLAB version.
Turi
am 8 Sep. 2013
Image Analyst
am 8 Sep. 2013
Bearbeitet: Image Analyst
am 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
am 8 Sep. 2013
vahide jafari
am 23 Feb. 2015
0 Stimmen
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 Kommentar
Image Analyst
am 23 Feb. 2015
Kategorien
Mehr zu Spreadsheets finden Sie in Hilfe-Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!