문제

My issue is with MCsolutionupdated() function in that I am unable to run it for 20,000+ iterations as I obtain the error "Edge vector must be monotonically non-decreasing.". Sometimes, I even obtain Inf elements (when I do not get this error) for final_matrix which does not make sense either. When I run Nielsennewupdated(casechoice, no_iterations) I am able to run it for as many simulations and I do not ever obtain Inf elements. So, I think there must be a problem with MCsolutionupdated().

function [final_matrix, thresh_strain] = MCsolutionupdated()

no_iterations = input('No. of iterations?:');

thresh_strain = zeros(1,no_iterations*16);

casechoice =input('Enter 1 for 1st Layup and 2 for 2nd layup:');

 J = Nielsennewupdated(casechoice, no_iterations);
 thresh_strain = J;


roundedValues = round(thresh_strain/.0001)*0.0001;
myUniqueValues = unique(roundedValues);
i = numel(myUniqueValues);
nelements  = hist(thresh_strain(:),myUniqueValues); 

for i=1:i
    percent(i)  = (nelements(1,i)/numel(thresh_strain))*100;
end

final_matrix = [myUniqueValues' percent'];

% uniqueValues,~,uniqueIndex] = unique(ans);
% frequency = accumarray(uniqueIndex(:),1)./numel(ans);

header = {'Threshold Strain' 'Probability of occurrence'};
xlswrite('results.xlsx', header) 
xlswrite('results.xlsx', final_matrix,'A2')

Thanks

도움이 되었습니까?

해결책

Your error is on this line (the error message probably even says as much):

nelements  = hist(thresh_strain(:),myUniqueValues);

The problem is that myUniqueValues is not "monotonically non-decreasing." This example produces the same error:

n  = hist(randi(3,[1 10]),[3 2 1]);

which results in

Error using histc
Edge vector must be monotonically non-decreasing.

Error in hist (line 92)
    nn = histc(y,edges,1);

I'm not sure what this is happening as unique is supposed to sort it's output. So I can't replicate your error exactly in R2013b. Perhaps you're running an older version of Matlab. I'd look at what the value of myUniqueValues is.

다른 팁

This type of errors is mainly due to the second argument of hist function not being monotonically non-decreasing

Change your unique line to:

myUniqueValues = unique(roundedValues,'sorted');

You probably have an old version that does not sort by default, but rather uses "stable" ordering.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top