# Cell arrray that stores with iteration a new set of values

• marellasunny
In summary, The speaker is trying to store the coordinates of intersections between two functions of x in an array without losing the previous iteration's values. They considered using a cell array but are unsure of how it works. They tried using the pre-defined function 'intersections(x,...)' to store the data, but it kept getting erased. They then suggest using a for loop to index the array and mention the importance of preallocating the array. They also note that in MATLAB, the index always starts with 1 and not 0.
marellasunny
Here,I have a pre-defined function called 'intersections(x,...) that finds the intersections between 2 functions of x.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 looksie at the code below.

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.

You just need to index the array somehow. For example,

A = zeros(1,5);
for i=1:5
A(i) = i+1;
end
A

This produces a 1x5 array A = [2 3 4 5 6]

If you know the size the array needs to be, it's always better to preallocate with zeros (outside of the loop of course).

Also in MATLAB at least, the index always starts with 1 (never 0)

## 1. What is a cell array in scientific research?

A cell array is a data structure used in scientific research to store and organize data in a tabular format. It is similar to a spreadsheet, but each cell can contain any type of data, including numbers, strings, and other arrays.

## 2. How does a cell array store data with iteration?

A cell array uses a loop or iterative process to store a new set of values. This means that the array will go through each cell, one by one, and assign a new value to each cell based on the specified iteration process.

## 3. What are the advantages of using a cell array for data storage?

There are several advantages to using a cell array for data storage in scientific research. These include the ability to store different types of data in a single array, the ability to easily add or remove data, and the ability to access and manipulate data using indexing and iteration.

## 4. Can a cell array be used for large datasets?

Yes, a cell array can be used for large datasets in scientific research. However, it is important to consider the memory and processing limitations of the computer or software being used, as large datasets may require more resources and may impact the speed and efficiency of operations.

## 5. How does a cell array differ from other data structures?

A cell array differs from other data structures, such as matrices and structures, in that it can store different types of data in a single array and does not have a fixed size. This makes it more versatile for storing and organizing data in scientific research, but may also require more computational resources for data manipulation.

• MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
3K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
7K
• MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
984
• Calculus and Beyond Homework Help
Replies
11
Views
1K
• MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
• Calculus and Beyond Homework Help
Replies
3
Views
1K
• Programming and Computer Science
Replies
29
Views
2K