图形句柄对象的完整结构是什么?

时间:2015-08-13 18:50:36

标签: matlab matlab-figure matlab-hg2

Mathworks再次做到了:我的古代R2012(由我的公司授予)返回一组很好的findall来识别图形窗口编号以响应

1) corrects several oversights in the posted code
2) works correctly
3) contains the logic that (generally) is always used to 
   add a node to the end of a linked list
4) demonstrates that to change the contents of a passed in pointer
   the simplest way is to pass '**' 
   and the caller passes the address of the pointer, not the contents of the pointer
5) uses consistent formatting
6) avoids unnecessary/misleading clutter/confusion in the definition of the struct
7) removes unnecessary parameters from functions
8) properly prototypes the functions 
   notice that the new_node() function prototype has '(void)'
   while the actual function body just has '()'

#include <stdio.h>
#include <stdlib.h>

struct node
{
    int val;
    struct node * next;
};

// prototypes
void          print_list( struct node * head);
struct node * new_node( void );
void          push( struct node ** head, int val);


int main ( void )
{

    struct node * test_list = NULL;

    push(&test_list, 1);
    push(&test_list, 2);

    print_list(test_list);

    return 0;
} // end function: main


// step through linked list, printing the val field from each node
void print_list( struct node * head)
{
    struct node * current = head;

    while (current != NULL)
    {
        printf("%d\n", current->val);
        current = current->next;
    }
} // end function: print_list


// create a new node
struct node * new_node()
{
    struct node * head2 = NULL;

    if( NULL == (head2 = malloc(sizeof( struct node))))
    { // then malloc failed
        // handle error, cleanup, and exit
    }

    return  head2;
} // end function: new_node


// append a new node to end of linked list
// need to use '**' so actual pointer in main() will be updated
void push( struct node ** head, int val)
{
    struct node * current = NULL;

    if (*head == NULL)
    { // then list is empty
        current = new_node();
        current->val = val;
        current->next = NULL;
        *head = current;
    }

    else
    {
        current = *head;

        while (current->next != NULL)
        {
            current = current->next;
        }

        /* now we can append a new node to linked list */
        current->next = new_node();
        current->next->val = val;
        current->next->next = NULL;
    }
} // end function: push

现在我有一个远程IM-ing的人因为我给他的代码在R2015下失败了因为{{1}}现在返回了一个数字句柄的结构。我无法使用他的系统(没有RDC),并且mathworks文档页面似乎没有指定图形句柄结构的元素。特别是,我想知道我是否仍然可以检索图窗口编号。有人知道吗?

1 个答案:

答案 0 :(得分:3)

当然。

currhandles(:).Number

将所有数字作为逗号分隔列表返回。

或指定您想要的数字:

currhandles(1).Number

顺序似乎是初始化的逆序。

或者,您可以定义两个匿名函数来直接获取数组:

figure(1); figure(2); figure(42);

getNumbers = @(x) [x.Number];
getFigureNumbers = @() getNumbers([findall(0,'type','figure')]);

getFigureNumbers()
ans =

    42     2     1