Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

Octave: How to assign the right dimensionality to an existing cell array to avoid "error: =: nonconformant arguments (op1 is 2x2x2, op2 is 2x2x2)"?

I am a beginner at Octave, that is why I will share something too obvious for the most.

cell_arr = cell(2,2,2);
cell_arr(2,2,2) = cell(2,2,2);

error: =: nonconformant arguments (op1 is 2x2x2, op2 is 2x2x2)

I am assigning an array of the same dimensionality as the cell_array, and it is not accepted. What should I change?


This is a spin-off from Please Explain Octave-Error : operator /: nonconformant arguments (op1 is 1x1, op2 is 1x10) and Error: nonconformant arguments (op1 is 1x3, op2 is 1x2) which both do not deal with cell arrays.

question from:https://stackoverflow.com/questions/65865401/octave-how-to-assign-the-right-dimensionality-to-an-existing-cell-array-to-avoi

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It's not clear what you're trying to do, but your understanding of cells seems to be a bit confused.

To make matters worse, I think you are coming across a bug: https://savannah.gnu.org/bugs/?func=detailitem&item_id=59637

I don't want to get too technical and confuse you even more, but what is happening here is this. We usually introduce cell arrays by saying this little story:

"There are two kinds of arrays: normal arrays, and cell arrays. Normal arrays always need to be 'rectangular', and contain elements of the same type. Cell arrays on the other hand, can contain elements of different types."

However, this isn't exactly true. It's a simplification. In reality, a 'cell' is simply a special kind of object; a container if you like. And a cell array then, is simply a normal array, whose elements are all 'cell objects'. In fact, the cell command is simply a shortcut way for creating an array of empty cells, nothing more.

More generally, cell arrays are indexed using {}, which opens up the cell object, and gives you its contents.

However, since they can also be thought of as normal arrays of 'cell objects', you can also index it with () like a normal array, and return the 'cell object' itself (as opposed to its contents).

E.g.

a = cell(1,2)   # this is equivalent to a = { [], [] }
a{1}   # returns an empty numerical array, which is what the first cell contains.
a(1)   # returns a cell object, which happens to contain an empty numerical array.

Regarding the bug you're coming across, octave seems to report the wrong size for the elements you're trying to access when it comes to multidimensional cell arrays. This has been reported. What you should have been getting was something like

Error: op1 is 1x1, op2 is 2x2x2

In other words: "you are trying to cram a 2x2x2 array (whose elements happen to be cell objects) into a space that only fits a single element (i.e. at position 2,2,2)."


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...