problem to get all values in for loop

2 views (last 30 days)
Why am I getting the last value repeating for every value in each cell. Please help.
Thank you.
for i=1:3
for j=1: 5
for u=1: length(U)
if ~isempty(GradeU1{j,i})
FF=GradeU1{j,i}(:,u);
for k1=1:length(GradeU1{j,i}(:,u))-2
k2=k1+1;
for k3=k1+2: length(GradeU1{j,i}(:,u))
F1=([FF(1:k1); FF(k2)]);
F2=([FF(1:k1); FF(k3)]);
condCdf1 = condCop('clayton',F1.',AlfaClay(i),length(F1));
condCdf2 = condCop('clayton',F2.',AlfaClay(i),length(F2));
[~,pair21,~] = SOUVIKCOP('clayton',[condCdf1,condCdf2],AlfaClay(i));
for L=1:length(cop1{j,i}{:,u}{1})-k1
cop1{j,i}{u}{k1+1}(L)=pair21 ; % each cell arrays should have
% (4,3,2,1) no . of data..Now, i get all the values of pair21 right, but while
% storing them in the cell arrays of cop1, only the last value is being stored
% for 4 times or 3 times or 2 times.
end
end
end
end
end
end
end
  2 Comments
Guillaume
Guillaume on 28 Jun 2019
Edited: Guillaume on 28 Jun 2019
Why am I getting the last value repeating for every value in each cell.
How can we know? Your code is not commented, you've given no explanation of what it is attempting to be doing, we don't know anything about the input variables and we don't know what condCop and what SOUVIKCOP do, and you don't even tell us what the last value refers to nor what variable in each cell applies to.

Sign in to comment.

Accepted Answer

Bob Thompson
Bob Thompson on 28 Jun 2019
I suspect you're getting the same result because you aren't changing the value of pair21 within the final loop.
for L=1:length(cop1{j,i}{:,u}{1})-k1
cop1{j,i}{u}{k1+1}(L)=pair21 ; % pair21 is assigned to each element of cop1{j,i}{u}{k1+1}, but pair 21 doesn't change in value

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!