MATLAB: How to put the results in a cell

arraycellthreshold

Hi,
I have a set of array (1×100 double) representing a set of threshold values and data of (136×136 double). What I want to do is based on the value of each element in the set of threshold value, the data of (136×136 double) will update independently until the last value of the threshold. Then, i want to make it the updated data as 1×100 cell. How can i do this?
I have try to wrote a code on it, but its look like the data is not updated according to the set of threshold values.
loadThres = load ('Pth_array.mat'); % load the threshold values
Pth = loadThres.Pth;
load_img = load ('img2.mat'); % load the data
img2 = load_img.img2;
Resolution=136;
for j=1:100 % get each threshold value
Val(1,j)=Pth(1,j);
for m = 1:Resolution;
for n = 1:Resolution;
if img2(m,n)<Val(1,j);img2(m,n)=0;end %threshold
if img2(m,n)>=Val(1,j);img2(m,n)=1;end
end
end
array{j}=img2;
end

Best Answer

Yasmin - your code starts with the first threshold value and then iterates over each element in img2 and does the following
if img2(m,n)<Val(1,j)
img2(m,n)=0;
end %threshold
if img2(m,n)>=Val(1,j)
img2(m,n)=1;
end
So the value is set to zero or one and once you have iterated over each one, the img2 matrix is contains only elements that are 0 or 1.
On the next iteration of the outer for loop, you choose the next threshold value but you continue to use img2 which will only have 0 or 1 elements. I think that you want to start with the original 136x136 matrix and apply the new threshold to it. Perhaps something like
for j=1:100 % get each threshold value
Val(1,j)=Pth(1,j);
img2 = load_img.img2;
% etc.