No video

MATLAB - fgetl and fgets for reading a line of text

  Рет қаралды 6,674

Painless Programming

Painless Programming

Күн бұрын

MATLAB - To read from a file in MATLAB, first open the file with fopen.
If fopen returns a -1, there was an error opening the file.
fgetl - read in a line at a time from the MATLAB file, does not keep the newline character
fgets - read in a line at a time from the MATLABE file, KEEP the newline character.
If you want to read data in as a data type other than a string, you can use
fscanf - read from a file, you can include format specifiers like %d (integers), %f (floating point numbers), %c (characters), %s (strings)

Пікірлер: 10
@camdendean9000
@camdendean9000 Жыл бұрын
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 Жыл бұрын
Thanks for taking the time to comment. Good luck with your thesis!
@Adil_shares
@Adil_shares 4 жыл бұрын
nice video
@PainlessProgramming
@PainlessProgramming 4 жыл бұрын
Thanks!
@sin3divcx
@sin3divcx Жыл бұрын
How can i take the second row with fgetl?
@PainlessProgramming
@PainlessProgramming Жыл бұрын
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
Adding Sound  MATLAB programs
2:43
Painless Programming
Рет қаралды 3,9 М.
Matlab 20: File Operations - Read and Write
10:10
Mahdi Farahikia
Рет қаралды 14 М.
Lehanga 🤣 #comedy #funny
00:31
Micky Makeover
Рет қаралды 30 МЛН
Little brothers couldn't stay calm when they noticed a bin lorry #shorts
00:32
Fabiosa Best Lifehacks
Рет қаралды 19 МЛН
WHO CAN RUN FASTER?
00:23
Zhong
Рет қаралды 44 МЛН
File I/O in MATLAB
48:34
Engineering Educator Academy
Рет қаралды 473
MATLAB file IO
6:14
Painless Programming
Рет қаралды 1,8 М.
Strings in MATLAB
5:44
RobertTalbertPhD
Рет қаралды 59 М.
Textscan and Fscanf in Matlab
9:39
Learnrope Tutorials
Рет қаралды 42 М.
1_3a How to read data from text files in MATLAB
8:20
Exquisite Square
Рет қаралды 30 М.
MATLAB: Load Multiple Files For Batch Processing (uigetfile)
11:26
Quick Codes with Daniel
Рет қаралды 20 М.
How to Extract Text from Scanned Documents with MATLAB
4:45
Script M-Files in MATLAB
10:00
RobertTalbertPhD
Рет қаралды 159 М.
Lehanga 🤣 #comedy #funny
00:31
Micky Makeover
Рет қаралды 30 МЛН