From: Braden on
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
From: Donn Shull on
"Braden " <bapeters007(a)gmail.com> wrote in message <i2n3mb$5sk$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

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
From: us on
"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
From: us on
"Braden " <bapeters007(a)gmail.com> wrote in message <i2n3mb$5sk$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

do NOT double post...
see your other thread...

us
From: Braden on
"us " <us(a)neurol.unizh.ch> wrote in message <i2n4k0$81e$1(a)fred.mathworks.com>...
> "Braden " <bapeters007(a)gmail.com> wrote in message <i2n3mb$5sk$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
>
> do NOT double post...
> see your other thread...
>
> us

Wasn't trying 2, i hit the submit button twice because of lag.