1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Textread of csv-file

  1. Feb 28, 2007 #1
    I'm sure that this will be a quite simple question, but I will not work for me. I try to read data from a csv-file with matlab(see under post). But is doesn't work... I try to skip the the first 9 ninen lines, because they are useless for the data analyses. I try the following line with matlab:
    [data] = textread('data.csv','','delimiter',',','emptyvalue',NaN)

    Can somebody help me to change this line? Thanks for every help!

    greetings,
    Erik

    0;63;1;63;500;1000;0;4
    0;1;1;150;1000;1500
    0;2;2;150;1000;1500
    0;3;3;150;1000;1500
    0;4;4;150;1000;1500
    0;5;5;150;1000;1000
    0;6;6;150;1000;1000
    0;7;7;150;1000;1000
    0;8;8;150;1000;1000
    1; 2; 792;2314; Led;-255; 3; 2; 1500; 7; 1; NaN; NaN
    2; 2; 892; 892; Led;-255; 6; 1; 1500; 7; 1; NaN; NaN
    3; 2; 835; 835; Led;-255; 9; 1; 1500; 7; 1; NaN; NaN
    4; 2; 881; 881; Led;-255; 12; 1; 1500; 7; 1; NaN; NaN
    5; 2; 560; 560; Led;-255; 15; 1; 1500; 7; 1; NaN; NaN
    6; 2; 507; 507; Led;-255; 18; 1; 1500; 7; 1; NaN; NaN
    7; 2; 652; 652; Led;-255; 21; 1; 1500; 7; 1; NaN; NaN
    8; 2; 704; 704; Led;-255; 24; 1; 1500; 7; 1; NaN; NaN
    9; 2; 502; 502; Led;-255; 27; 1; 1500; 7; 1; NaN; NaN
    10; 2; 738;1495; Led;-270; 3; 2; 1500; 7; 1; NaN; NaN
    11; 2; 901; 901; Led;-270; 6; 1; 1500; 7; 1; NaN; NaN
    12; 2; 767; 767; Led;-270; 9; 1; 1500; 7; 1; NaN; NaN
    13; 2; 940; 940; Led;-270; 12; 1; 1500; 7; 1; NaN; NaN
    14; 2; 852; 852; Led;-270; 15; 1; 1500; 7; 1; NaN; NaN
    15; 2; 848; 848; Led;-270; 18; 1; 1500; 7; 1; NaN; NaN
    16; 2; 853; 853; Led;-270; 21; 1; 1500; 7; 1; NaN; NaN
    17; 2; 546; 546; Led;-270; 24; 1; 1500; 7; 1; NaN; NaN
    18; 2; 521; 521; Led;-270; 27; 1; 1500; 7; 1; NaN; NaN
    19; 2; 655;1494; Led;-285; 3; 2; 1500; 7; 1; NaN; NaN
    20; 2; 661; 661; Led;-285; 6; 1; 1500; 7; 1; NaN; NaN
    21; 2; 901; 901; Led;-285; 9; 1; 1500; 7; 1; NaN; NaN
    22; 2; 707; 707; Led;-285; 12; 1; 1500; 7; 1; NaN; NaN
    23; 2; 569; 569; Led;-285; 15; 1; 1500; 7; 1; NaN; NaN
    24; 2; 819; 819; Led;-285; 18; 1; 1500; 7; 1; NaN; NaN
    25; 2; 777; 777; Led;-285; 21; 1; 1500; 7; 1; NaN; NaN
    26; 2; 886; 886; Led;-285; 24; 1; 1500; 7; 1; NaN; NaN
    27; 2; 544; 544; Led;-285; 27; 1; 1500; 7; 1; NaN; NaN
    28; 2; 567;1492; Led; 0; 3; 2; 1500; 7; 1; NaN; NaN
    29; 2; 893; 893; Led; 0; 6; 1; 1500; 7; 1; NaN; NaN
    30; 2; 834; 834; Led; 0; 9; 1; 1500; 7; 1; NaN; NaN
    31; 2; 702; 702; Led; 0; 12; 1; 1500; 7; 1; NaN; NaN
    32; 2; 942; 942; Led; 0; 15; 1; 1500; 7; 1; NaN; NaN
    33; 2; 673; 673; Led; 0; 18; 1; 1500; 7; 1; NaN; NaN
    34; 2; 917; 917; Led; 0; 21; 1; 1500; 7; 1; NaN; NaN
    35; 2; 767; 767; Led; 0; 24; 1; 1500; 7; 1; NaN; NaN
    36; 2; 543; 543; Led; 0; 27; 1; 1500; 7; 1; NaN; NaN
    37; 2; 766;1494; Led; 15; 3; 2; 1500; 7; 1; NaN; NaN
    38; 2; 603; 603; Led; 15; 6; 1; 1500; 7; 1; NaN; NaN
    39; 2; 858; 858; Led; 15; 9; 1; 1500; 7; 1; NaN; NaN
    40; 2; 704; 704; Led; 15; 12; 1; 1500; 7; 1; NaN; NaN
    41; 2; 840; 840; Led; 15; 15; 1; 1500; 7; 1; NaN; NaN
    42; 2; 625; 625; Led; 15; 18; 1; 1500; 7; 1; NaN; NaN
    43; 2; 795; 795; Led; 15; 21; 1; 1500; 7; 1; NaN; NaN
    44; 2; 649; 649; Led; 15; 24; 1; 1500; 7; 1; NaN; NaN
    45; 2; 928; 928; Led; 15; 27; 1; 1500; 7; 1; NaN; NaN
    46; 2; 526;1492; Led; 30; 3; 2; 1500; 7; 1; NaN; NaN
    47; 2; 793; 793; Led; 30; 6; 1; 1500; 7; 1; NaN; NaN
    48; 2; 964; 964; Led; 30; 9; 1; 1500; 7; 1; NaN; NaN
    49; 2; 825; 825; Led; 30; 12; 1; 1500; 7; 1; NaN; NaN
    50; 2; 513; 513; Led; 30; 15; 1; 1500; 7; 1; NaN; NaN
    51; 2; 698; 698; Led; 30; 18; 1; 1500; 7; 1; NaN; NaN
    52; 2; 957; 957; Led; 30; 21; 1; 1500; 7; 1; NaN; NaN
    53; 2; 817; 817; Led; 30; 24; 1; 1500; 7; 1; NaN; NaN
    54; 2; 843; 843; Led; 30; 27; 1; 1500; 7; 1; NaN; NaN
    55; 2; 646;1493; Led; 45; 3; 2; 1500; 7; 1; NaN; NaN
    56; 2; 742; 742; Led; 45; 6; 1; 1500; 7; 1; NaN; NaN
    57; 2; 745; 745; Led; 45; 9; 1; 1500; 7; 1; NaN; NaN
    58; 2; 686; 686; Led; 45; 12; 1; 1500; 7; 1; NaN; NaN
    59; 2; 790; 790; Led; 45; 15; 1; 1500; 7; 1; NaN; NaN
    60; 2; 620; 620; Led; 45; 18; 1; 1500; 7; 1; NaN; NaN
    61; 2; 681; 681; Led; 45; 21; 1; 1500; 7; 1; NaN; NaN
    62; 2; 667; 667; Led; 45; 24; 1; 1500; 7; 1; NaN; NaN
    63; 2; 988; 988; Led; 45; 27; 1; 1500; 7; 1; NaN; NaN
     
    Last edited: Feb 28, 2007
  2. jcsd
  3. Feb 28, 2007 #2
    Is the file actually comma-separated or is it semicolon-delimited as shown in your post?
     
  4. Feb 28, 2007 #3
    The file is exactly like this post, I also try to change the comma in textread in an a ;
     
  5. Feb 28, 2007 #4

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    Then it is not a csv file.
     
  6. Feb 28, 2007 #5
    and why not? It should be a csv-file... and how can I read it in another extension?
     
  7. Feb 28, 2007 #6

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    If it is semi colon delimited then it is NOT comma delimited. CSV stands for comma separated values and implies a comma delimited file.
     
  8. Mar 1, 2007 #7
    but how can I read this? :(
     
  9. Mar 1, 2007 #8

    Integral

    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    What are the parameters in the textread command?

    Do you have to define your data structure?
     
  10. Mar 1, 2007 #9

    Dr Transport

    User Avatar
    Science Advisor
    Gold Member

    Either strip out the header and change your delimiter to a semi-colon or use C-style syntax to read the file within Matlab.
     
  11. Mar 1, 2007 #10
    I have part of the solution. I can use the following line:
    [M{1:13}]=textread('ee0100.csv','%d%d%d%d%s%d%d%d%d%d%d%d%d','headerlines',9,'delimiter',';');

    Problem is now that I get lines like:
    And simply use M(:,1) doesn't give me the contents but [63x1 double]. So is it possible to change that?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Textread of csv-file
  1. Csv reader (Replies: 1)

  2. File output (Replies: 4)

  3. C++ csv file reading (Replies: 2)

Loading...