Prev: Placing a multidimensional array in a 2D array
Next: MTech project on Matlab/Simulink in the field of electronics
From: Braden on 27 Jul 2010 14:15 "Andy " <myfakeemailaddress(a)gmail.com> wrote in message <i2n6g0$bv7$1(a)fred.mathworks.com>... > 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'? Srry, it was a typo. What I meant to say is that even if the file says true, and it reads in true, the strcmp doesn't figure that out and always returns false.
From: us on 27 Jul 2010 14:22 On Jul 27, 8:15 pm, "Braden " <bapeters...(a)gmail.com> wrote: > "Andy " <myfakeemailaddr...(a)gmail.com> wrote in message <i2n6g0$bv...(a)fred.mathworks.com>... > > 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'? > > Srry, it was a typo. What I meant to say is that even if the file says true, and it reads in true, the strcmp doesn't figure that out and always returns false.- Hide quoted text - > > - Show quoted text - well... then you're not telling the whole story(!)... v1='true'; v2={'true'}; r={ strcmp(v1,'true'),strcmp(v1,'false') strcmp(v2,'true'),strcmp(v2,'false') }; disp(r); %{ [1] [0] [1] [0] %} us
From: Andy on 27 Jul 2010 14:26
You need to be more specific in what you post. According to everything you say, your code should of course work. Try this code and post the result here: % note: no semicolons. show all the output constantPath_str = textscan(fid1, '[%s]\n', 'CommentStyle', '%', 'delimiter', ']') constantPath_str=constantPath_str(1) class(constantPath_str) % note: added line boolcheck=strcmp(constantPath_str, 'true') if boolcheck==1 constantPath=1 else constantPath=0 end isequal(boolcheck, constantPath) % this last line should return 1 % so you don't actually need the intermediate boolcheck |