Search code examples
matlabmatlab-uitable

count number of rows in uitable


I'm having trouble counting the number of rows in my uitable.

data={'for' '32' '1'
      '123' 'tired' '3g'
      '0' 'door' 'roof'};
w=uitable('data',data,'position',[100 100 100 100])

I have tried the command height, but i get an error saying

Undefined function 'height' for input arguments of type 'double'.

Error in boundary_conditions (line 9)
height(w)

Solution

  • The first part initialize the uitable and display it:

    data={'for' '32' '1'                               
    '123' 'tired' '3g'                                 
    '0' 'door' 'roof'};                                
    w=uitable('data',data,'position',[100 100 100 100])
    

    now in order to get/set object properties one may follow this howto. Here is an example of getting for your needs:

    prop = {'data','position'};                                                       
    attributes = get(w,prop);
    >> attributes
    
    attributes = 
    
        {3x3 cell}    [1x4 double]
    
    >> attributes{1}
    
    ans = 
    
        'for'    '32'       '1'   
        '123'    'tired'    '3g'  
        '0'      'door'     'roof'
    
    >> size(attributes{1},1)
    
    ans =
    
         3