[scilab-Users] can not read all words in a ascii file

Mike Page Mike at Page-One.Waitrose.com
Wed Feb 9 11:02:01 CET 2011


Hi Loic,

Your file contains two bytes before the beginning of the string (0x01,
0x00).  These characters cannot be correctly parsed as a string type.

If you add y=mfscanf(2,fd4,'%c') before the reading of the strings, then you
find the first string in the vector is "Mesure" as expected.

There are more non-ASCII characters after the final string ("Alu"), which
cause the random extra strings at the end of your vector.  You can either
read a limited number from the file (first parameter not == -1), or discard
the last elements of the string vector.

There are lots of ways to make a single string from the vector.  One way is
s=sprintf("%s ",x).  The space after %s causes the elements to be separated
by a single space, if that's what you want.

HTH,
Mike.

  -----Original Message-----
  From: Loïc GIROD [mailto:Loic.Girod at esstin.uhp-nancy.fr]
  Sent: 09 February 2011 09:19
  To: users at lists.scilab.org
  Subject: [scilab-Users] can not read all words in a ascii file


  Hello !



  I try to read the characters in the attached ASCII file.

  I would like to use the strings to make a legend in a graph.



  I use the following code :

  fd4 = mopen("P_70",'r')

  x=mfscanf(-1,fd4,'%s')



  but I get :

  x  =



  !                !

  !                 !

  !des              !

  !                 !

  !points           !

  !                 !

  !de               !

  !                 !

  !transformations  !

  !                 !

  !simple           !

  !                 !

  !DSC              !

  !                 !

  !Essai            !

  !                 !

  !A                !

  !                 !

  !Air              !

  !                 !

  !Alu              !

  !                 !

  !                 !

  !                 !

  !A                !

  !                 !

  !A                !

  !                 !

  !A                !

  !                 !

  !A                !

  !                 !

  !A                !

  !                 !

  !D                !

  !                 !

  !D                !





  As you can see, the first word is missing and I don’t understand why.

  Then I have not found how to convert x in a single string.



  Many thanks for the help



  Best regards



  Loïc


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20110209/25239d0b/attachment.htm>


More information about the users mailing list