Bird
0
0

Which of the following is the correct syntax to open a file named 'data.txt' for writing in MATLAB?

easy📝 Syntax Q12 of 15
MATLAB - File I/O
Which of the following is the correct syntax to open a file named 'data.txt' for writing in MATLAB?
Afid = fopen('data.txt', 'w');
Bfid = fopen('data.txt', 'r');
Cfid = fopen('data.txt', 'a');
Dfid = fopen('data.txt', 'x');
Step-by-Step Solution
Solution:
  1. Step 1: Understand fopen modes

    'r' is read-only, 'w' is write (creates or overwrites), 'a' appends, 'x' creates new file but errors if exists.
  2. Step 2: Choose mode for writing

    To write fresh data, use 'w' mode to open file for writing.
  3. Final Answer:

    fid = fopen('data.txt', 'w'); -> Option A
  4. Quick Check:

    Open file for writing = 'w' mode [OK]
Quick Trick: 'w' mode in fopen opens file for writing (overwrite) [OK]
Common Mistakes:
  • Using 'r' mode which is read-only
  • Using 'a' when overwrite is needed
  • Confusing 'x' mode with 'w'

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More MATLAB Quizzes