MATLAB String Operations and File I/O Flashcards
6 cards from real MATLAB practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 MATLAB String Operations and File I/O flashcards as text
What is the correct way to open a file for writing in MATLAB?
Answer: fid = fopen('file.txt', 'w')
fopen opens a file and returns a file identifier; the 'w' mode opens the file for writing, creating it if it does not exist.
Which MATLAB function replaces occurrences of a substring within a string?
Answer: strrep
strrep(str, old, new) replaces all occurrences of the old substring with the new substring in str.
What does `fprintf(fid, '%d\n', x)` do in MATLAB?
Answer: Writes formatted integer x followed by newline to the file with identifier fid
fprintf writes data to a file or screen using C-style format specifiers, with fid=1 for stdout and fid=2 for stderr.
How do you split a string by a delimiter in MATLAB?
Answer: strsplit(str, delimiter)
strsplit splits a string at each occurrence of the specified delimiter and returns a cell array of substrings.
Which function converts a string to lowercase in MATLAB?
Answer: lower
lower converts all uppercase letters in a string to their lowercase equivalents.
What does `xlswrite('data.xlsx', M)` do in MATLAB?
Answer: Writes matrix M to an Excel file named data.xlsx
xlswrite writes array data to an Excel spreadsheet file, creating it if it does not exist.