cell arrray that stores with every iteration a new set of values
Info
This question is closed. Reopen it to edit or answer.
Show older comments
Here,I have a pre-defined function called intersections(x,....) that finds the intersections between 2 functions of x and stores the (x,y1) and (x,y2) values directly into the output cell/array.Now,for each iteration of the loop,I get a set of (x,y1) and (x,y2) values. I want to store them in an array without losing the previous iteration's values. So,I figured I'd use a cell array except I can't decipher its working mechanism.Someone,please help me with this. Have a look at the code below.[I pasted the whole code at the end].
for i=1:5
for j=1:5
%functions f1 and f2
y1=@(x)C.*(x)./((x.^p)+1);
y2=@(x)(r.*(1-(x./q)));
[a{i,j},b{i,j}] = intersections(x,y1(x),x,y2(x),1);
%a line of plot commands follow[not important] end
end
I initially used [xout,yout]= intersections(x,y1(x),x,y2(x),1); to store the coordinates of the intersections but it kept getting erased out after each iteration.I want the whole data stored coordinates stored in 1 cell array.
1 Comment
Jan
on 10 Jan 2013
I do not understand the question. What is erased? Why is y1 and y2 redefined in each iteration? Why is intersections called with the same inputs in each iteration?
Answers (1)
Azzi Abdelmalek
on 10 Jan 2013
Edited: Azzi Abdelmalek
on 10 Jan 2013
clear
y1=@(x)C.*(x)./((x.^p)+1);
y2=@(x)(r.*(1-(x./q)));
for ii=1:5
for jj=1:5
[aa,bb]= intersections(x,y1(x),x,y2(x),1);
a{ii,jj}=aa
b{ii,jj}=bb
end
end
% avoid using i and j as variables, they are reserved to represent complex numbers
This question is closed.
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!