How can I view numeric array elements in edit text box, in Guide?

In a simple form I would like to display the primes in specified range (in the edit text box "vypis_prvcsl") . I use the edit text control, but it sends the error:
Error using matlab.ui.control.UIControl/set
While setting property 'String' of class 'UIControl':
Value must be a character array, numeric array, or cell array.
Error in untitled4>pushbutton1_Callback (line 114)
set(handles.vypis_prvcsl, 'String', a2)
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in untitled4 (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in
matlab.graphics.internal.figfile.FigFile/read>@(hObject,eventdata)untitled4('pushbutton1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating UIControl Callback
The code used for pushbutton: function pushbutton1_Callback(hObject, eventdata, handles)
a1 = (str2double(get(handles.min, 'String'))) : (str2double(get(handles.max, 'String')));
a2 = isprime(a1);
a3 = numel(a1(a2));
set(handles.rozsah, 'String', a3);
set(handles.vypis_prvcsl, 'String', a2)

 채택된 답변

Stephen23
Stephen23 2017년 9월 16일
편집: Stephen23 2017년 9월 16일
a2 is of type logical, and is definitely not string, numeric, or cell array. Did you read the error message?
One simple fix is to make convert it to numeric by appending the plus operation:
set(handles.vypis_prvcsl, 'String', +a2)

댓글 수: 2

The implicit conversion by the + operator might be confusing. Perhaps this is "easier":
set(handles.vypis_prvcsl, 'String', num2str(a2))
Stephen, thank you for your answer - but the edit text field disappeared and reply
"Warning: Single line Edit Controls can not have multi-line text".
Jan, it works properly, thank you very much (with little edit, but on my side).
set(handles.vypis_prvcsl, 'String', num2str(a1(a2)))

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Characters and Strings에 대해 자세히 알아보기

질문:

2017년 9월 16일

댓글:

2017년 9월 16일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by