From: Braden on
"us " <us(a)neurol.unizh.ch> wrote in message <i2n4i3$45s$1(a)fred.mathworks.com>...
> "Braden " <bapeters007(a)gmail.com> wrote in message <i2n3tg$kgs$1(a)fred.mathworks.com>...
> > I've got the following code:
> >
> > constantPath_str = textscan(fid1, '[%s]\n', 'CommentStyle', '%', 'delimiter', ']')
> > constantPath=0; %Initalize boolean variable to false.
> > constantPath_str=constantPath_str(1)
> > boolcheck=strcmp(constantPath_str, 'true') %Check if the read data is = to true or false.
> > if boolcheck==1
> > constantPath=1;
> > %tau0=textscan(fid1, '[%n]\n', 'CommentStyle', '%') %Always read, only used if constantTime == true. [s] - tau0 = P^-1, where P is the scattering rate.
> > else
> > constantPath=0;
> > end
> >
> > In this code, I read a value (either true or false) from a .txt file and store it in constantPath_str. I then try to use strcmp to see if constantPath_str is equal to true (without the quotes). If it's = to true, i need to set the constantPath to 1. My problem is that it doesn't seem to realize that the value It read in is equal to true. It reads the data in perfectly, but it can't seem to compare it top the word true. What have i done wrong in my code? Please help me, i'm a matlab n00b an really need to figure this out stat.
> > All i want to do is see if the value of the variable constantPath_str is equal to the word true, then if it is, set constantPath to 1. If I need to convert between array types to make the comparasion, please tell me how.
> >
> >
> > Thanks
> >
> > Braden
>
> well... it would be most helpful if you could show the content of the var CONSTANTPATH_STR
> after this operation:
>
> constantPath_str = textscan(fid1, '[%s]\n', 'CommentStyle', '%', 'delimiter', ']')
>
> us

the value is 'false' or false (when I check the variable editor it has 'false' in the first cell, don't know if it's reading single quotes or it puts them there because it's a string). I just need strcmp 2 work.
From: Donn Shull on
"Braden " <bapeters007(a)gmail.com> wrote in message <i2n5as$os6$1(a)fred.mathworks.com>...
> "us " <us(a)neurol.unizh.ch> wrote in message <i2n4i3$45s$1(a)fred.mathworks.com>...
> > "Braden " <bapeters007(a)gmail.com> wrote in message <i2n3tg$kgs$1(a)fred.mathworks.com>...
> > > I've got the following code:
> > >
> > > constantPath_str = textscan(fid1, '[%s]\n', 'CommentStyle', '%', 'delimiter', ']')
> > > constantPath=0; %Initalize boolean variable to false.
> > > constantPath_str=constantPath_str(1)
> > > boolcheck=strcmp(constantPath_str, 'true') %Check if the read data is = to true or false.
> > > if boolcheck==1
> > > constantPath=1;
> > > %tau0=textscan(fid1, '[%n]\n', 'CommentStyle', '%') %Always read, only used if constantTime == true. [s] - tau0 = P^-1, where P is the scattering rate.
> > > else
> > > constantPath=0;
> > > end
> > >
> > > In this code, I read a value (either true or false) from a .txt file and store it in constantPath_str. I then try to use strcmp to see if constantPath_str is equal to true (without the quotes). If it's = to true, i need to set the constantPath to 1. My problem is that it doesn't seem to realize that the value It read in is equal to true. It reads the data in perfectly, but it can't seem to compare it top the word true. What have i done wrong in my code? Please help me, i'm a matlab n00b an really need to figure this out stat.
> > > All i want to do is see if the value of the variable constantPath_str is equal to the word true, then if it is, set constantPath to 1. If I need to convert between array types to make the comparasion, please tell me how.
> > >
> > >
> > > Thanks
> > >
> > > Braden
> >
> > well... it would be most helpful if you could show the content of the var CONSTANTPATH_STR
> > after this operation:
> >
> > constantPath_str = textscan(fid1, '[%s]\n', 'CommentStyle', '%', 'delimiter', ']')
> >
> > us
>
> the value is 'false' or false (when I check the variable editor it has 'false' in the first cell, don't know if it's reading single quotes or it puts them there because it's a string). I just need strcmp 2 work.

read my reply about indexing in your other thread.

Donn
From: us on
"Braden "
> the value is 'false' or false (when I check the variable editor it has 'false' in the first cell, don't know if it's reading single quotes or it puts them there because it's a string). I just need strcmp 2 work.

well... it does...

v='false';
tf=strcmp(v,'false')
% tf = 1
v={'false'};
tf=strcmp(v,'false')
% tf = 1

us
From: Andy on
Here's Donn's reply from the other thread in full (let's stick to this one thread):

>Hi Braden,
>textscan returns a cell aray of strings. so your code:
>constantPath_str=constantPath_str(1)
>returns a cell ie {'true'} rather than 'true'
>you should use cell indexing notation
>constantPath_str=constantPath_str{1}
>to get the string value
>good luck,
>Donn


However, I don't think this is the issue, since:

strcmp({'true'},'true') % returns 1

However, this seems to answer everything:

>the value is 'false' or false

What exactly is the problem if strcmp doesn't identify 'false' as 'true'?
From: Andy on
>All i want to do is see if the value of the variable constantPath_str is equal to the word true, then if it is, set constantPath to 1.

By the way, if this is your goal, you can make your code considerably more readable by doing simply:

constantPath = strcmp(constantPath_str,'true');

There's no need to create the intermediate boolcheck, and then there's no need for the if/then statement.