What is the best/right way to get a warndlg message/string?
6 views (last 30 days)
Show older comments
Renan Campos
on 5 Jun 2020
Answered: Walter Roberson
on 5 Jun 2020
Hi,
I am trying to read/get a warndlg box String content.
What I did so far to read the String, is as follows:
>>x = warndlg() %creates a warning dialog box with a default String 'This is the default warning string.'
>>xx = get(x, 'Children');
>>xx = xx(2);
>>xxx = get(xx,'Children');
>>xxx = xxx(5);
>>get(xxx,'String')
ans =
'This is the default warning string.'
From here I can use this string in a conditional statement to decide what the script should do next.
But the way I am doing this seems to be quite "brute force"... so I wander if there is any other way of doing this.
For context sake, basically I have a warndlg called by an "internalfunction.m" function, which I am not allowed to edit at this point (otherwise I suppose a better ideia would be checking the warndlg string in its creating point...); and I have another "wrapper.m" code that tries to get information out of this "internalfunction.m" warning diaglo box.
It would be so much easier if it was possible to get the string more straightly... like:
>>get(get(0,'Children'),'String') %get warndlg handler if it was not directly availble...
But such 'String' proprierty is not avail like that...
Any suggestions?
Thank you!
0 Comments
Accepted Answer
Walter Roberson
on 5 Jun 2020
x = warndlg();
char(get(findobj(x,'type','Text'), 'String'))
The String property by itself will be a cell array of character vector, so char() is used to extract the content.
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!