Home > Archive > Matlab > August 2007 > single quote
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
| Corinna Schmitt 2007-08-30, 4:29 am |
| Hallo,
I want to make a string which has single quotes in it. My
idea is:
a='''%s';
for i=1:5
a=[a ' s%'];
end
a=[a ''''];
The result is:
a =
'%s s% s% s% s% s%'
This looks partly wright. But a should look like this:
'%s s% s% s% s% s%' which means without \.
Can anyone help me?
Corinna
| |
|
|
"Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag
news:fb5t9d$4pt$1@fred.mathworks.com...
> Hallo,
> I want to make a string which has single quotes in it. My
> idea is:
>
> a='''%s';
> for i=1:5
> a=[a ' s%'];
> end
> a=[a ''''];
>
> The result is:
>
> a =
>
> '%s s% s% s% s% s%'
>
> This looks partly wright. But a should look like this:
> '%s s% s% s% s% s%' which means without \.
>
> Can anyone help me?
>
> Corinna
Hi Corinna,
first of all, this is a case where repmat can help, second, use 4 times ' to
get a string containing the single quote, so altogether:
a = ['''' repmat('%s ', 1, 5) '''']
Titus
| |
| Michael Wild 2007-08-30, 4:29 am |
| Corinna Schmitt wrote:
> Hallo,
> I want to make a string which has single quotes in it. My
> idea is:
>
> a='''%s';
> for i=1:5
> a=[a ' s%'];
> end
> a=[a ''''];
>
> The result is:
>
> a =
>
> '%s s% s% s% s% s%'
>
> This looks partly wright. But a should look like this:
> '%s s% s% s% s% s%' which means without \.
>
> Can anyone help me?
>
> Corinna
a string with single quotes:
s = 'he said ''hi''';
hth
michael
| |
| Corinna Schmitt 2007-08-30, 4:29 am |
| Hallo,
sorry, but your solutions causes errors again:
xyz = ['''' repmat('%s', 1, 5) '''']
[patient1, patient2, patient3, patient4, patient5] = ...
textread
(source,xyz,factorsPerPatient, 'delimiter', '\t');
The error message is:
??? Trouble reading literal string from file (row 1, field
1) ==> 1 1 2 1 2\n
Error in ==> textread at 177
[varargout{1:nlhs}]=dataread('file',vara
rgin{:});
Error in ==> BeispielV3 at 26
[patient1, patient2, patient3, patient4, patient5] = ...
If I run the program with the original command ...textread
(source,'%s%s%s%s%s',factorsPerPatient, 'delimiter', '\t');
it works fine.
Any idea?
Corinna
| |
|
|
"Corinna Schmitt" <csc@mathworks.com> schrieb im Newsbeitrag
news:fb61oo$a45$1@fred.mathworks.com...
> Hallo,
>
> sorry, but your solutions causes errors again:
>
> xyz = ['''' repmat('%s', 1, 5) '''']
>
> [patient1, patient2, patient3, patient4, patient5] = ...
> textread
> (source,xyz,factorsPerPatient, 'delimiter', '\t');
>
>
> The error message is:
>
> ??? Trouble reading literal string from file (row 1, field
> 1) ==> 1 1 2 1 2\n
>
> Error in ==> textread at 177
> [varargout{1:nlhs}]=dataread('file',vara
rgin{:});
>
> Error in ==> BeispielV3 at 26
> [patient1, patient2, patient3, patient4, patient5] = ...
>
> If I run the program with the original command ...textread
> (source,'%s%s%s%s%s',factorsPerPatient, 'delimiter', '\t');
> it works fine.
>
> Any idea?
>
> Corinna
Hi Corinna,
just leave out the '''' at the beginning and the end:
repmat('%s', 1, 5) is already a string. When you call the original command,
you need to add the ' at the beginning and the end to construct a string.
xyz = repmat('%s', 1, 5) ;
[patient1, patient2, patient3, patient4, patient5] = ...
textread
(source,xyz,factorsPerPatient, 'delimiter', '\t');
should work fine.
Titus
| |
| Corinna Schmitt 2007-08-30, 8:15 am |
| Hallo Titus,
>
> xyz = repmat('%s', 1, 5) ;
>
> [patient1, patient2, patient3, patient4, patient5] = ...
> textread
> (source,xyz,factorsPerPatient, 'delimiter', '\t');
>
> should work fine.
Thanks, it is working. Now another question which I posted
a second a go with the title: textscan.
I want to read a tab-delimited txt-file. At the moment I
realisied it with textread. It works. Can any one show me
how it would work with textscan? I cannot realize it with
the Matlab-HELP. The original txt-file comes from exel and
consist of 3 rows and 5 columns.
The aim is to have the input in one variable from where I
than extract every information I need.
My solution with txtread:
[patient1, patient2, patient3, patient4, patient5] = ...
textread(source,'%s%s%s%s%s',3, 'delimiter', '\t');
In this case the bad thing is that I need to specifiy the
wright number of variables in the first breaket and
afterwards I have 5 for-loops to handle the informations on
into one variable - overviewTable=cell
(factorsPerPatient,numberOfPatients) - where the column i
stand for the patient i.
The inputfile looks like this:
1 1 2 1 2 <--row1
23 4 5 23 5 <--row2
6 7 8 9 10 <--row3
In each row the numbers are devided by tab! So the input
file consists of three rows.A new line seems to be realized
with /n.
Can you help me in this case,too?
Corinna
| |
| Corinna Schmitt 2007-08-30, 8:15 am |
| Thanks,
another friend could help me. The solution is:
xyz = repmat('%s', 1, 5) ;
fid = fopen(source);
inputData = textscan(fid, xyz);
fclose(fid);
Corinna
|
|
|
|
|