writelines — Write text lines to a file.
writelines(lines, filename) writes each supplied text value as a line in a host file.
Syntax
status = writelines(lines, filename)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
lines | Any | Yes | — | Text lines to write. |
filename | StringScalar | Yes | — | Destination text file. |
Returns
| Name | Type | Description |
|---|---|---|
value | Any | Result value. |
How writelines works
linesmay be a string scalar, string array, character vector, or cell array of scalar text. String-array and cell elements are written in linear order.filenamemust be scalar host text. Native integer and resident numeric inputs are rejected rather than converted to text.- RunMat writes a line ending after every input element, including the last. The
LineEndingoption accepts"unix","windows","pc", or"mac". - The current implementation overwrites the destination file.
WriteModeandEncodingoptions are not yet implemented.
Example
Write a string array as separate lines
lines = ["alpha"; "beta"];
writelines(lines, "names.txt")Expected output:
`names.txt` contains `alpha` and `beta` on separate lines.Using writelines with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how writelines changes the result.
Run a small writelines example, explain the result, then change one input and compare the output.
FAQ
Does writelines gather GPU values?⌄
No. Its inputs are text and filesystem options, so numeric resident values are rejected before provider access.
Related Io functions
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Import
Json
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.