Hi, I am trying to retrieve array of sum of 3 numbers (x,y,z) each has a range of 1-255, in such a way that each sum is different from others. I have coded but I couldn't get 100% distinct sum, below result gives Average = 255, Max = 255 , MIN = (254 but I want 255 every time if possible). So each variable's value can be decoded back form the distinct sum. For example sum = 3 is only possible when we have (1+1+1) but for Sum = 4 we have 3 different possible and then it is not decodable; (1+1+2),(1+2+1),(2+1+1), sum = 4. I would be happy if anyone of you can debug this problem. Thank you.
%Updated.
%Input and Expected Output%
% Input Output
% [1,1,2] sum=>4
% [1,2,1] sum=>[different than above]
% [2,1,1] sum=>[distinct from others]
% [3,1,1] sum=>5
% ... ...
%Code%
clear;clc; for n = 1:1000 %using Iteration to have 1000 different results that are stored in Difference(n,:) which gives Uniqueness values of each result.
Array = zeros(255,5); Array(:,1:3) = randi(255,255,3); for k = 1:length(Array); Array(k,4) = sum(Array(k,1:3)); end for l = 1:length(Array); firstVal = Array(l,1)*0.7; secondVal = Array(l,2)*0.9+firstVal; thirdVal = Array(l,3)*1.4*secondVal; Array(l,5) = sum([firstVal,secondVal,thirdVal]); end%253Avg
% first = Array(l,1)*0.7;
% second = Array(l,2)*0.9 + first;
% third = Array(l,3)*1.4 + second;
oldunique_Length = length(unique(Array(:,4))); newunique_Length = length(unique(Array(:,5))); Difference(n,:) = [oldunique_Length,newunique_Length];end%average no. of distinct sum = 255/255, Max value is 255 and MIN value is 254. It is still not 100% because I am getting 254 as a MIN. Everytime I should be able to get 255 (all rows must be different from others)
["OLD UniqueIds (AVG,MAX,MIN)",round(mean(Difference(:,1))),max(Difference(:,1)),min(Difference(:,1));"NEW UniqueIds (AVG,MAX,MIN)",round(mean(Difference(:,2))),max(Difference(:,2)),min(Difference(:,2))]
Best Answer