Structures with for loop
11 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Geoff Hayes
il 31 Lug 2016
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.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!