MATLAB - fgetl and fgets for reading a line of text

แชร์
ฝัง
  • เผยแพร่เมื่อ 24 พ.ย. 2024

ความคิดเห็น • 10

  • @camdendean9000
    @camdendean9000 2 ปีที่แล้ว

    These videos are truly stellar! Information is delivered at a digestible rate without making the videos far too long. Thank you for helping me with my Master's Thesis in coastal engineering!

    • @PainlessProgramming
      @PainlessProgramming  2 ปีที่แล้ว

      Thanks for taking the time to comment. Good luck with your thesis!

  • @Adil_shares
    @Adil_shares 4 ปีที่แล้ว +1

    nice video

  • @sin3divcx
    @sin3divcx 2 ปีที่แล้ว

    How can i take the second row with fgetl?

    • @PainlessProgramming
      @PainlessProgramming  2 ปีที่แล้ว +2

      If you call fgetl twice, the first time you call it you will be reading in the first line. The second time you call it you will be reading in the second. line.

  • @MyMpc1
    @MyMpc1 5 ปีที่แล้ว

    Thanks for the video. What is the code in purple? I don't understand what it is.

    • @PainlessProgramming
      @PainlessProgramming  5 ปีที่แล้ว

      Thanks for watching the video.
      MATLAB will display any strings (something in quotes) in purple. In my video I had several strings:
      1) fid=fopen('test.txt', 'r'); - This fopen command contains a string with the file name 'test.txt' and a string with 'r'- for reading mode. Both strings contain quotes around them.
      2) fprintf('line=%s***', line); - The fprintf command contains a string with characters that will be printed just as they are in the string: line= and *** and special format specifier characters like %s or %d . A %s stands for a string and will substitute the contents of the variable line in place of %s.
      3) fscanf(fid, '%d', [1 3]); - The fscanf command contains a string with %d, this indicates that the data read in from the file will be integers (no decimal places)

    • @MyMpc1
      @MyMpc1 5 ปีที่แล้ว

      @@PainlessProgramming That's really kind of you to reply - thank you. Sorry for the brevity of my initial question. I was getting more and more frustrated as I'd been search matlab docs for hours. Normal strings I'm fine with, but I hadn't come across special format specifiers before you answered my question, so thank you very much. I've seen them used a lot without explanation and it can be confusing to a newbie ;-)
      I just searched matlab docs under 'special format specifiers' to see if there is a documents about them and I tried a few variations of the term, but nothing came up. Do you know what they may be called under the matlab help documents for me to read further? Thanks so much for your help Heather!

    • @PainlessProgramming
      @PainlessProgramming  5 ปีที่แล้ว

      There is more info on format specifiers here www.mathworks.com/help/matlab/matlab_prog/formatting-strings.html