Structures with for loop

조회 수: 11 (최근 30일)
Ozge Moral
Ozge Moral 2016년 7월 31일
댓글: Ozge Moral 2016년 7월 31일
I have a problem like
"Conversion to double from struct is not possible.
Error in calisma7 (line 9)
A(1,j).sample(1,i)=initialization(new_a,new_b,10);"
My code is below. Code creates structures in structure until condition satisfies. But,at second iteration,it gives above error. When i tried to make A(1,2).sample(1,1) = initial... , it gave correct answer, but it didn't in loop.
while sz>0.0001
for j=1:length(A)
for i=1:length(A(1,j).AntObserved)
p = A(1,j).AntObserved(i);
d = A(1,j).interval{p};
new_a =min(d);
new_b =max(d);
A(1,j).sample(1,i)=initialization(new_a,new_b,10);
B(1,j).sample(1,i)=UpdatePhe(10);
[A(1,j).sample(1,i),B(1,j).sample(1,i)]=initial2(A(1,j).sample(1,i),B(1,j).sample(1,i),10,f);
A(1,j).sample(1,i)=Moving(A(1,j).sample(1,i),B(1,j).sample(1,i),10);
temp1 = A.sample;
temp2 = B.sample;
end
end
A=temp1;
B=temp2;
sz=A.sz;
end
I couldn't find what problem is. About structure field name? In addition, i should add initialization function:
function [ StartingValue] = initialization( a,b,n )
% [a,b] is interval of function that minimum points will search.
% n is pre-assigned number, # of subinterval.
% Intervals and midpoint of these intervals are described.
% a=a;
% b=b;
% n=n;
sz=(b-a)/n;
StartingValue.sz = sz;
StartingValue.interval = {};
StartingValue.x ={};
StartingValue.fn =[];
StartingValue.eta =[];
StartingValue.allowed = [];
StartingValue.Ants = ones(n,1);
StartingValue.AntObserved = {};
for i=1:n
StartingValue.interval{i} = [a+(i-1)*sz a+i*sz];
StartingValue.x{i} = a+(i-0.5)*sz;
StartingValue.fn(i) =0;
end
end
  댓글 수: 7
Geoff Hayes
Geoff Hayes 2016년 7월 31일
Ozge - you need to provide a working sample of your code that can easily demonstrate the problem. What is your UpdatePhe or initial2 methods? How do they relate to the code that you posted in your question? I also suggest using the MATLAB debugger to step through your code.
Ozge Moral
Ozge Moral 2016년 7월 31일
A stores 1x6 sample. These 6 sample structure each stores samples.(ex:A.sample.sample.sample) But i can't explain exactly. Thanks for your interest. I will try to find another way.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by