Copying text from edit box in GUI to matlab report.

1 vue (au cours des 30 derniers jours)
Sudhanshu Goel
Sudhanshu Goel le 29 Juil 2016
Commenté : Sudhanshu Goel le 1 Août 2016
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 commentaires
Shameer Parmar
Shameer Parmar le 29 Juil 2016
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 le 30 Juil 2016
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).

Connectez-vous pour commenter.

Réponse acceptée

Geoff Hayes
Geoff Hayes le 30 Juil 2016
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 commentaire
Sudhanshu Goel
Sudhanshu Goel le 1 Août 2016
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by