Reference no: EM132171570
Using Matlab
Cells can be placed inside cells, creating complex nested structures to store information.
Write a function celldepth(A, unused) that returns the depth of the input A (the second input unused should be part of your function definition, but it is not unused in calculation of the depth).
Depth of a cell array is defined as the maximum of the depths of its contents plus 1.
The depth of non-cell data is considered zero. You may assume that the input will not have a cell depth greater than 100.
>> celldepth( {1 [2 3]}, 0 ) ans = 1 >> celldepth( {1 {2 3}}, 0 ) ans = 2
NOTE: Because of a limitation in the server, you cannot recursively call your main function. If you want to use a recursive solution, then define your solution as a subfunction and you'll be able to call your subfunction recursively. e.g.,:
function depth = celldepth(a,unused) % The main function does nothing but calls the subfunction celldepth2. depth = celldepth2(a); function [depth] = celldepth2(a) %... You can now call celldepth2 within celldepth2.