When asking for help, you need to assume that we don't know what you are trying to do. What do you expect the output of your code to be? What do you expect Theta to be, how do you know it is not right? Also, in general, it is helpful for those that are trying to help you to provide a minimum working example (https://en.wikipedia.org/wiki/Minimal_working_example) that demonstrates the error that you are seeing. For example, are you seeing the issue with a smaller matrix or only for the size that you provide?
Thank you for providing actual example that demonstrates your
issue---almost, that is. Please forgive my harping on details:
everybody on this list, including myself, really enjoys assisting
other people, so I launched into your example trying to say
something helpful, but ran into trouble almost from the start---so I
decided to use my prerogative as an old fogey to pontificate a
little bit. Basically, I am asking you to please help me help you.
In general, I noticed that recently this list had a series of help
requests that are hard to act on, which is why I think it's time to
step back and think about this whole co-op help arrangement.
Basically, we are all using Octave, which is quite powerful but
sometimes tricky to use. In other words, we are trying to do
something that almost certainly is possible but may require some
insight or trick that eludes us, and we need other people to
understand what we want, and come up with a suggestion based on
their insight and experience.
Therefore, we decide to ask for help. Now, we have two issues: our
original puzzle, and then the second problem of explaining it to
others in a concise way that would enable others to get on with
helping us. That sounds depressing, but the good news is that the
second issue is actually a blessing in disguise. I strongly believe
that having to explain something to others is actually a good
exercise that improves our own insight in this very thing: I often
experienced a sudden flash of inspiration while trying to explain to
others what is it that I don't understand.
In particular, let's take your question and restate it in a way that
would be easier to act on. First, let's simplify: you use two 6 by
20 data arrays, which is awkward to look at: they can be smaller and
easier to deal with; also, instead of just giving their values, I
specify them in a way that allows me to load them up:
By the way, I find that having variables (like data and Data or
theta and Theta) that have the same name with the only difference
being the case of some letters is confusing---and I am easily
confused so I would avoid that, personally--but we'll keep them this
way for simplicity here.
Then, I think you are showing two code snippets that process the
data and asking why the result is different. Note that it is a good
practice to indent your code.
Now, this is easier to deal with than your
original question: I can cut-and-paste this into my Octave and
look into the details.
Firstly, the second way has two nested
loops--but the inner loop uses the same variable, so it overwrites
the outer loop variable. This is almost never correct--and if it
was intended, I would definitely put a lot of comments near it to
explain the logic.
In any case, your theta is constructed as a 2D
array in first case, and as 3D array with three indices in the
second case, so of course Theta will end up being 2D and 3D,
Again, you have to explain what are you trying
to calculate in each case, and what result do you expect.