필터 지우기
필터 지우기

Copying text from edit box in GUI to matlab report.

조회 수: 4 (최근 30일)
Sudhanshu Goel
Sudhanshu Goel 2016년 7월 29일
댓글: Sudhanshu Goel 2016년 8월 1일
I have created a GUI in which there is an editbox where user enters certain text. This text is then required to be added in a report which is generated at a later stage. I am using a code which is something like this:
%%Code to get text entered in editbox
handles.text=get(handles.editbox,'string');
%%Code to add text to matlab report (via DOM API)
text_to_be_added=Paragraph(handles.text);
append(report,text_to_be_added);
Now my problem is as long as the text entered in editbox is a single line the result is fine (Text is copied as it is from editbox to report). But if I add a new line in the text which is to be entered in editbox (by pressing enter key), the text which is printed in report is totally disoriented.
Eg: If the text in edit box is: This month is july. Then the text saved in my report is: This month is july.
But if the text in edit box is:
This month is
july.
Then the text saved in report looks like this:
Tjhuilsy .m o n t h i s
Is their any way this problem can be fixed. I know adding '\n' rather than pressing enter key will add a new line in report but is their any other way in which matlab can recognize enter key press to add a new line automatically.
  댓글 수: 2
Shameer Parmar
Shameer Parmar 2016년 7월 29일
Are you sure, you can enter the data in multiple lines in single editbox ? I guess Its not possible... Single edit box is not allow to enter the data in multiple lines.. Please confirm this..
Geoff Hayes
Geoff Hayes 2016년 7월 30일
Shameer - Yes, multiple lines of text can be entered into an edit text box (so long as the Max property is greater than the Min property).

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

채택된 답변

Geoff Hayes
Geoff Hayes 2016년 7월 30일
Sudhanshu - you mention that typing \n works. Can you perhaps inject this character after the user has typed in the text into the edit box? Note that
handles.text=get(handles.editbox,'string');
will be a cell array of strings, one for each line in the edit box. So you could create a single line string from these multiple strings, concatenating each together and separating each by a \n. For example,
strData = get(handles.edit1,'String');
handles.text = strData{1};
if size(strData,1) > 1
for k=2:size(strData,1)
handles.text = [handles.text '\n' strData{k}];
end
end
However, I don't know if this will be sufficient when adding it your report.
  댓글 수: 1
Sudhanshu Goel
Sudhanshu Goel 2016년 8월 1일
Thanks a lot Geoff. Your approach works like a charm. The code needed minor tweaks.
strData = get(handles.edit1,'String');
handles.text = strData(1,:);
if size(strData,1) > 1
for k=2:size(strData,1)
handles.text = [handles.text '\n' strData(k,:)];
end
end
Once again thanks for your help.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Environment and Settings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by