-3

If we come to the following line of code in MATLAB:

reshape(dataSet{i},1, 200*200);
  • Here, dataset{j} seems to be an element in a cell array. Is that right? Since we are using reshape, can we say that that element is an array?
  • When we use reshape, we define the dimensions (i.e; m,n). In the code above, is m=1 and n=200*200? But, why wasn't n written as 400 for instance? Is there some reason for writing it in the syntax that we see?

Thanks.

Simplicity
  • 47,404
  • 98
  • 256
  • 385

1 Answers1

2

dataSet is a cell array but you can't assume that dataset{j} is an array. Reshape will work on strings and cell arrays as well:

reshape({1,2,3,4},2,2)

ans =

    [1]    [3]
    [2]    [4]

>> reshape('abcd',2,2)

ans =

ac
bd

There's not an obvious reason to write 200*200 unless 200 is important to understanding what is being computed.

Molly
  • 13,240
  • 4
  • 44
  • 45
  • Presumably `dataset{j}` is a square array of whatever datatype. Equivalent flattening would be achieved by replacing `200*200` with `[]`. Maybe the writer wants to emphasise the dimensions for whatever reason as Molly suspects; or maybe they're unaware/indifferent to the `[]` functionality and can't be bothered to calculate & hard code the product. – benxyzzy May 11 '17 at 21:13