Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Determine whether array is full

Options
  • 07-12-2010 10:49pm
    #1
    Registered Users Posts: 61 ✭✭


    Hey guys do you know how to determine if an array in MATLAB is full? I know that to determine if its empty it is:

    TF = isempty(A)

    Any ideas??


Comments

  • Closed Accounts Posts: 4,564 ✭✭✭Naikon


    [DM]Frink wrote: »
    Hey guys do you know how to determine if an array in MATLAB is full? I know that to determine if its empty it is:

    TF = isempty(A)

    Any ideas??

    Not sure about matlab, but in a procedural way you could just use an integer as a flag to determine if the array is full. If the count is >= to the number of elements in the list, it's full. Keep the count local.
    You could also check if the last usable element has a non null/non default value. You could even write a subroutine to check an input array. Sry, I don't know Matlab so I might not be the best for advice :\


  • Registered Users Posts: 4,769 ✭✭✭cython


    [DM]Frink wrote: »
    Hey guys do you know how to determine if an array in MATLAB is full? I know that to determine if its empty it is:

    TF = isempty(A)

    Any ideas??

    What do you define as an array being "full"? Obviously an array being empty is that it has no elements, i.e. either zero rows, zero columns, or both. By a full array do you mean that there is at least one element? Or do you want to check that all the elements have a non-zero value? If the former, then surely inverting the return of the isempty call would suffice:
    TF = ~isempty(A)
    
    If the latter, then you could do either an element by element check, or (for a 2 dimensional matrix) something like
    TF  = ~min(min(abs(A)))
    
    which will return 1 to TF if A has any non-zero elements


  • Registered Users Posts: 61 ✭✭[DM]Frink


    Its just to check if there is any element inside the array. Thanks guys for your help I got it sorted with your help


Advertisement