# Questions related to saving multiple arrays in one variable

**URL:** <https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759>\
**Category:** General Usage\
**Tags:** question, arrays\
**Created:** [October 14, 2021, 2:31pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759 "2021-10-14T14:31:23Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 2:31pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759/1 "2021-10-14T14:31:23Z")

</div>

I have a variable “fi”, which stores a global grid of elevations (units: meters), and another variable “DL” that stores 26 depth levels. Below are my scripts for creating some land/sea masks:

```julia
function f1(fi, DL)
    A = [];
    for i in 1:length(DL)
        B = fi .> -DL[i];
        A = [A, B];
    end
    A
end
L0 = f1(fi, DL);

```

When I checked the created mat file in Matlab, I encountered multiple issues. Would anyone please help?

1. Why does my L0{1} give me the below answer, when it should be a grid of zeros and ones? BTW, my L0{2} gives me the correct grid.  
2×1 cell array  
{ 2×1 cell }  
{1440×720 logical}

2. Why does L0 only contains two grids, instead of the 26 grids the loop produces?

Many thanks!

---

<div class="post-metadata">

**Author:** ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Post date:** [October 14, 2021, 2:35pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759/2 "2021-10-14T14:35:39Z")

</div>

> [@leon](#):
>
> ` A = [A, B];`

I think you want `push!(A,B)` here, but anyway it is hard to know because we can’t run your code and it is not clear what exactly you want as an output.

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 2:42pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759/3 "2021-10-14T14:42:56Z")

</div>

That solved my problem beautifully.

Thank you so much!

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 14, 2021, 5:14pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759/4 "2021-10-14T17:14:51Z")

</div>

@leon, fyi the `f1` function could be written conveniently as a comprehension:

```julia
f1(fi, DL) = [fi .> -DL[i] for i in 1:length(DL)]

```

---

<div class="post-metadata">

**Author:** ![leon](https://avatars.discourse-cdn.com/v4/letter/l/dc4da7/32.png) [@leon](https://discourse.julialang.org/u/leon)\
**Post date:** [October 14, 2021, 9:14pm UTC](https://discourse.julialang.org/t/questions-related-to-saving-multiple-arrays-in-one-variable/69759/5 "2021-10-14T21:14:50Z")

</div>

I just tried it and it worked like a charm!

Many thanks for sharing that trick!
