new lines from an edit text component

Hi,
I am building a small gui using GUIDE and have a multiline edit text box. I would like to consider each line seperately. Is it possible to obtain the string in the edit box as a cell array with an element for each line?

댓글 수: 3

Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
What do you mean? If you run Str=get(hObject,'String'), it's already a cell array of strings.
Daniel Shub
Daniel Shub 2011년 11월 14일
In r2011a I get an nxm character array.
Fangjun Jiang
Fangjun Jiang 2011년 11월 14일
Then would cellstr(get(hObject,'String')) be enough?

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

 채택된 답변

Daniel Shub
Daniel Shub 2011년 11월 14일

0 개 추천

Assuming h is the handle to your uicontrol ...
s = get(h, 'string');
scell = mat2cell(s, ones(size(s, 1), 1), size(s, 2));

추가 답변 (1개)

Walter Roberson
Walter Roberson 2011년 11월 14일

0 개 추천

One only gets back a character array from a uicontrol if one initialized to a character array or character vector and does not change it afterwards.
There are an exceptions to this:
  • if one created a popup or listbox from a character vector that has embedded '|' characters, then each '|' marks the end of a string, and the character vector with '|' will be converted to a cell array.
edit boxes do not break lines at '|' characters.
My recollection is that if a user edits a multi-line edit box then they will get a cell array back even if the original was a character array or character vector.
I do not recall at the moment what happens for a single-line edit box that is initialized to a character vector and then edited by the user.

카테고리

도움말 센터File Exchange에서 Cell Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by