Skip to main content
1-Visitor
December 17, 2015
Question

3D iteration

  • December 17, 2015
  • 3 replies
  • 1580 views

Dear all,

I have a problem with the 3D iteration. Firstly, I construct an initial jxk matrix. Then, I try to iterate the matrix and to build up a nested matrix. I don't understand where the problem is and I am wondering if there is a better way to program this idea. I have attached the file. Thank you very much for your kind help!! 

3d iteration.bmp

3 replies

24-Ruby IV
December 17, 2015

1-Visitor
December 17, 2015

Valery, in your program B is just equal to MMM.  The program stops at "return MMM" and the second half is not evaluated - that's why you no longer get the error.

J J Lin, note that Valery deleted your line i = i + 1 because it does nothing.  The very next step redefines i based on your iteration from 0 to 3 (or 0 to 2 in Valery's program).

1-Visitor
December 17, 2015

It's hard to follow what you're attempting to do.  What do you want as the final result?

23-Emerald IV
December 17, 2015

From Valery's reaction I infer that you've run in this trouble with your loop i 0...3.

With three dimensions you should run from 0...2, not 0...3 (that would be 4 dimensions?).

Success!
Luc

Nope. Valery's adaptation throws no error because the program is exited before it even gets to that loop.

The problem lies in the fact that you cannot refer to an array element that doesn't exist.

While you can create new array elements by just defining them, using the column indexer (<0>) may be problematic,

and  successfully assigning to individual items of a new nested matrix with (BM<0>[i)[j,k is plain impossible.

It fails already here: