Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
reading multi-line strings from uicontrol (edit)

Subject: reading multi-line strings from uicontrol (edit)

From: Tim Braun

Date: 19 Nov, 2008 13:59:02

Message: 1 of 2

hey folks,

I've got a big problem with reading strings from the edit-uicontrol. I have a GUI to let the user type in some words/sentences. For that, they could be multi-lined.

Example:

This is the first sentence.
The second one got a new line

Of course, these lines are seperated by the newline character ('\n')

My problem is, that if I quiery the edit-field for the string by

str = get(Edit,'String');

my variable str contains the example above (you can check this by leaving out the semicolon in the code-line).

But, and thats the problem, if I try to write the string to a file, the written string looks like this:

TThhies siesc otnhde ofnier sgto ts ean tneenwc el.i n e

You might notice, that all the characters, that have been typed to the edit-box are present in this type of character-lattuce, but I cant point out how to handle this string. It gets even worse if I try to use some of these textread, sprintf, strread or whatever functions.

Hope you guys can help me!?

Thanks!

Subject: reading multi-line strings from uicontrol (edit)

From: Steven Lord

Date: 19 Nov, 2008 14:24:21

Message: 2 of 2


"Tim Braun" <rubbish@gmx.info> wrote in message
news:gg1635$f79$1@fred.mathworks.com...
> hey folks,
>
> I've got a big problem with reading strings from the edit-uicontrol. I
> have a GUI to let the user type in some words/sentences. For that, they
> could be multi-lined.
>
> Example:
>
> This is the first sentence.
> The second one got a new line
>
> Of course, these lines are seperated by the newline character ('\n')
>
> My problem is, that if I quiery the edit-field for the string by
>
> str = get(Edit,'String');
>
> my variable str contains the example above (you can check this by leaving
> out the semicolon in the code-line).
>
> But, and thats the problem, if I try to write the string to a file, the
> written string looks like this:
>
> TThhies siesc otnhde ofnier sgto ts ean tneenwc el.i n e
>
> You might notice, that all the characters, that have been typed to the
> edit-box are present in this type of character-lattuce, but I cant point
> out how to handle this string. It gets even worse if I try to use some of
> these textread, sprintf, strread or whatever functions.
>
> Hope you guys can help me!?

Remember, MATLAB is column-major.


str = ['Hello'; 'world'];
fprintf('%c', str) % should give 'Hweolrllod', going down the columns of str
fprintf('\n');
fprintf('%c', str') % should give 'Helloworld', going down the columns of
str' (i.e. across the rows of str)
fprintf('\n');


So your original text was:

s = ['This is the first sentence. '; 'The second one got a new line']

--
Steve Lord
slord@mathworks.com

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us