Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Determine whether array is full

  • 07-12-2010 10:49PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 Posts: 4,846 ✭✭✭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, Registered Users 2 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