0

I'm struggling with determining the probability of occurrence of unique elements in thresh_strain matrix (which can be seen below as a 100 x 16). I was trying to use the code at the bottom to do this, but I get an equal probability of occurrence associated with each of the elements, whereas I want the probability of occurrence associated with unique elements in thresh_strain.

function [thresh_strain] = MCsolution()

no_iterations = 100;

thresh_strain = zeros(100, 16);

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

for i=1:no_iterations
for j=1:16  
J = Nielsennew(casechoice);  
thresh_strain(i,j) = J(1, j);  
end  
end

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

Thanks

Jojo
  • 1,117
  • 2
  • 15
  • 28

1 Answers1

1

It is not really clear from the title and description, but I suppose you may be looking for something like this:

myUniqueValues = unique(myMatrix);
nelements  = hist(myMatrix(:),myUniqueValues); 
%plot(myUniqueValues,nelements)

Basically calculating how often each unique value occurs. From here getting the corresponding percentage is of course trivial.

Dennis Jaheruddin
  • 21,208
  • 8
  • 66
  • 122
  • Thanks for the answer. Sorry I mistakenly wrote that I was looking to get the probability of occurrence of each of the elements. I am actually looking to find the probability of occurrence of Unique elements in my Matrix. Would you know how I could this? – Jojo Feb 17 '14 at 13:04
  • @Jojo Perhaps you just see ones because the first unique elements only occur once. The occurence of unique elements should be exactly what you get when you use this code fragment, perhaps you should try it with a small scale example first, for instance: `myMatrix = [1:4; 3:6]`. Have edited the question to contain a validation plot. – Dennis Jaheruddin Feb 17 '14 at 13:09
  • Sorry to keep bringing this up, but I'm a bit confused. When I look at myUniqueValues I get several repeating numbers. So, if I wanted to know the frequency of a particular value via `nelements = hist(myMatrix(:),myUniqueValues)`, surely I should get more than 1? Thanks again – Jojo Feb 17 '14 at 13:21
  • @Jojo Please post a small part of your data if these tips dont help: I suspect that the numbers appear to be repeated because of significance. Example: `[1 1+1e-6]`. You can see the difference by using `format long`, you can throw their values on one pile by rounding `myMatrix` **before** creating the histogram, or you can confirm that they are different. If the first two elements of `myUniqueValues` appear to be the same, try `myUniqueValues(2)-myUniqueValues(1)`. Probably it is not exactly zero. – Dennis Jaheruddin Feb 17 '14 at 13:27
  • Thanks.I've added this to the code that I initially posted: myUniqueValues = unique(thresh_strain); myUniqueValues = round(myUniqueValues/.0001)*0.0001; nelements = hist(thresh_strain(:),myUniqueValues); for i=1:16*no_iterations percent(i) = (nelements(1,i)/numel(thresh_strain))*100; end final_matrix = [myUniqueValues percent'];. I am essentially trying to get unique elements (where, if a number occurs multiple times I will show it only once. I'm not sure how to do this) in 1 coloumn and its associated percentage of occurence in the 2nd coloumn – Jojo Feb 17 '14 at 14:45