MathMath

Help › Functions

Files

readImage writeImage readTable readWav wavRate READPRN WRITEPRN APPENDPRN READ WRITE READFILE READBIN WRITEBIN READRGB READ_IMAGE READBMP WRITEBMP WRITERGB READ_RED READ_GREEN READ_BLUE READ_HLS READ_HSV

readImage("name") MathMath’s own

An attached picture as a matrix of its red, green and blue values, 0 to 255, in three blocks side by side.

Files reach a worksheet through Files on the toolbar, or Attach files… when the sheet says it needs some: the file is loaded into the sheet, kept by its name (capitals don't matter) and saved inside the worksheet. The name can also be a web address starting with http:// or https://, if that picture is attached under it. A picture of 50 pixels wide and 40 high gives a 40 by 150 matrix: the red block, then green, then blue. Loading a picture with Files writes the readImage line for you, assigned to a name you choose.

To work on the colors one by one, split the answer with imageChannels; toGray gives a gray image. Show a result as a picture with an image region. writeImage saves one.

Refused

  • A name that isn't in quotes.
  • A folder path: only a file name or a web address is accepted.
  • A file that isn't attached to the worksheet, which says to load it with Files.
P≔readImage(”photo.png”)
G≔toGray(P)
ditherAtkinson(G,2)

Reads or writes a file, so its answer depends on the file.

writeImage("name.png", M) MathMath’s own

Saves an image matrix as a picture file, a .png, .jpg or .webp, and gives back the matrix.

A plain matrix is written as gray levels 0 to 255, and a vector of three matrices (R; G; B) as color. The file isn't written to a folder: the browser offers it to save, and the region shows the outcome. Give only a name, such as "result.png", because a web page can't choose where on the computer to write. A matrix with the color blocks side by side is gray to this function: split it into three with imageChannels first.

Refused

  • A name that isn't in quotes.
  • A folder path, such as "C:/out.png".
  • Any ending but .png, .jpg, .jpeg or .webp.
  • Something that isn't an image: a matrix of plain numbers, or three of them.
M≔(0255​12864​)
W≔writeImage(”result.png”,M)

Reads or writes a file, so its answer depends on the file.

readTable("name") MathMath’s own

An attached data file, such as a CSV, as a matrix, one row for each line.

Files reach a worksheet through Files on the toolbar, or Attach files… when the sheet says it needs some: the file is loaded into the sheet, kept by its name (capitals don't matter) and saved inside the worksheet. Loading a data file with Files writes the readTable line for you; a Mathcad data-reading component in an imported sheet becomes one too.

Each line is split at commas, or if there are none at tabs, or else at spaces. If every cell is a number the answer is a matrix of numbers. If any isn't, a cell that is a number stays one and the rest become strings, so a header row can come along with the data. An empty cell is 0. Text in double quotes keeps its commas.

Refused

  • A name that isn't in quotes.
  • A folder path: only the name of an attached file.
  • A file that isn't attached.
  • A spreadsheet, .xls or .xlsx: save it as CSV and load that.
  • An empty file.
D≔readTable(”measurements.csv”)
D0,1​=

Reads or writes a file, so its answer depends on the file.

readWav("name.wav") MathMath’s own

An attached WAV sound file as a matrix with a column for each channel, samples between −1 and 1.

Files reach a worksheet through Files on the toolbar, or Attach files… when the sheet says it needs some: the file is loaded into the sheet, kept by its name (capitals don't matter) and saved inside the worksheet. A mono file gives one column and a stereo file two, with a row for every sample. Samples of 8, 16, 24 and 32 bits and 32- or 64-bit floating point are read and all scaled to run from −1 to 1. wavRate gives the sampling rate.

Pass a column to fft or the filters to work on the sound.

Refused

  • A name that isn't in quotes.
  • A folder path.
  • A file that isn't attached.
  • A file that isn't a WAV file, or has no sound data, or uses a sample format other than those listed.
S≔readWav(”tone.wav”)
fs​≔wavRate(”tone.wav”)
x≔fft(S⟨0⟩)

Reads or writes a file, so its answer depends on the file.

wavRate("name.wav") MathMath’s own

The sampling rate of an attached WAV file, in samples per second.

The answer carries the unit 1/s, so a time between samples is 1/wavRate("tone.wav"). The file is attached as for readWav, which gives its samples.

Units

The answer is in 1/s (hertz).

Refused

  • A name that isn't in quotes.
  • A folder path.
  • A file that isn't attached, or isn't a readable WAV file.
fs​≔wavRate(”tone.wav”)
Δt≔fs​1​

Reads or writes a file, so its answer depends on the file.

READPRN("path") Mathcad’s: refused here

Mathcad's reader for a data file as a matrix: recognized here, but refused; use readTable.

In Mathcad this reads a text file of numbers into a matrix. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the file with Files on the toolbar instead: it writes a readTable line, and the same file gives the same matrix.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
D≔READPRN(”data.prn”)
D=

Reads or writes a file, so its answer depends on the file.

WRITEPRN("path") Mathcad’s: refused here

Mathcad's writer of a matrix to a text file: recognized here, but refused.

In Mathcad this writes a matrix to a text data file, replacing it. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

To save a picture use writeImage. Numbers can be copied from a result.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
M≔(13​24​)
WRITEPRN(”out.prn”,M)

Reads or writes a file, so its answer depends on the file.

APPENDPRN("path") Mathcad’s: refused here

Mathcad's appender of a matrix to the end of a text file: recognized here, but refused.

In Mathcad this adds a matrix to the end of a text data file. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

See WRITEPRN. Nothing here writes data to a file.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
M≔(5​6​)
APPENDPRN(”out.prn”,M)

Reads or writes a file, so its answer depends on the file.

READ("path") Mathcad’s: refused here

Mathcad's reader of the next value from a file, one for each line that uses it: recognized here, but refused.

In Mathcad this is a scalar reader: each line that uses it takes the next number from the named file, so it needs the file kept open and its place remembered. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

A sheet here has no such position in a file. Load the whole file with Files, as readTable, and use its elements.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
a≔READ(”values.dat”)
a=

Reads or writes a file, so its answer depends on the file.

WRITE("path") Mathcad’s: refused here

Mathcad's writer of one value after another to a file, one for each line that uses it: recognized here, but refused.

In Mathcad this is a scalar writer: each line that uses it adds the next number to the named file. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

There is nothing to replace it with here, and nothing is written.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
WRITE(”values.dat”,3)

Reads or writes a file, so its answer depends on the file.

READFILE("path", "type") Mathcad’s: refused here

Mathcad's reader of a data file of a given type, such as a spreadsheet or text file: recognized here, but refused.

In Mathcad this reads a data file, in the type you name, into a matrix. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the file with Files. A text or CSV file becomes a readTable line; a spreadsheet needs saving as CSV first.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
D≔READFILE(”table.csv”,”delimited”)
D=

Reads or writes a file, so its answer depends on the file.

READBIN("path", "type", …) Mathcad’s: refused here

Mathcad's reader of a binary file as a vector of numbers: recognized here, but refused.

In Mathcad this reads the raw numbers of a binary file into a vector. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

A binary file of sound can be loaded with Files and read with readWav. Other binary files can't be read here.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
v≔READBIN(”samples.bin”,”double”)
v=

Reads or writes a file, so its answer depends on the file.

WRITEBIN("path", "type", …) Mathcad’s: refused here

Mathcad's writer of numbers as a binary file: recognized here, but refused.

In Mathcad this writes numbers to a binary file. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Nothing here writes binary data.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
v≔⎝⎛​123​⎠⎞​
WRITEBIN(”samples.bin”,”double”)

Reads or writes a file, so its answer depends on the file.

READRGB("path") Mathcad’s: refused here

Mathcad's reader of a picture as one matrix, the red, green and blue blocks side by side: recognized here, but refused; use readImage.

In Mathcad this reads a picture file into one matrix three times as wide as the picture. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files instead: readImage gives the same layout, so the rest of the sheet works on it as it did.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
P≔READRGB(”photo.jpg”)
toGray(P)

Reads or writes a file, so its answer depends on the file.

READ_IMAGE("path") Mathcad’s: refused here

Mathcad's reader of a picture as one matrix of gray levels: recognized here, but refused; use readImage and toGray.

In Mathcad this reads a picture file into a matrix of gray values. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files, then toGray of readImage gives the same kind of matrix.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
G≔READ_IMAGE(”photo.bmp”)
G=

Reads or writes a file, so its answer depends on the file.

READBMP("path") Mathcad’s: refused here

Mathcad's reader of a bitmap file as a matrix of gray levels: recognized here, but refused; use readImage and toGray.

In Mathcad this reads a bitmap picture into a matrix of gray values. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files, then use toGray on readImage.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
G≔READBMP(”photo.bmp”)
G=

Reads or writes a file, so its answer depends on the file.

WRITEBMP("path") Mathcad’s: refused here

Mathcad's writer of a matrix as a gray bitmap file: recognized here, but refused; use writeImage.

In Mathcad this writes a matrix of gray values as a bitmap file. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Use writeImage with a name such as "result.png": the browser offers the file to save.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
M≔(0255​2550​)
WRITEBMP(”out.bmp”,M)

Reads or writes a file, so its answer depends on the file.

WRITERGB("path") Mathcad’s: refused here

Mathcad's writer of a color picture from one matrix, the blocks side by side: recognized here, but refused; use writeImage.

In Mathcad this writes a color picture file from a matrix three times as wide as the picture. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Use writeImage with a vector of three matrices, which imageChannels can make from a wide matrix.

Refused

  • Any call: it always gives the note about Files and doesn't write anything.
C≔joinChannels(R,G,B)
WRITERGB(”out.bmp”,C)

Reads or writes a file, so its answer depends on the file.

READ_RED("path") Mathcad’s: refused here

Mathcad's reader of the red values of a picture as a matrix: recognized here, but refused; use readImage and imageChannels.

In Mathcad this reads the red channel of a picture file into a matrix. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files; then imageChannels(readImage(…)) gives the three channels and index 0 is the red one.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
C≔READ_RED(”photo.jpg”)
C=

Reads or writes a file, so its answer depends on the file.

READ_GREEN("path") Mathcad’s: refused here

Mathcad's reader of the green values of a picture as a matrix: recognized here, but refused; use readImage and imageChannels.

In Mathcad this reads the green channel of a picture file into a matrix. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files; then imageChannels(readImage(…)) gives the three channels and index 1 is the green one.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
C≔READ_GREEN(”photo.jpg”)
C=

Reads or writes a file, so its answer depends on the file.

READ_BLUE("path") Mathcad’s: refused here

Mathcad's reader of the blue values of a picture as a matrix: recognized here, but refused; use readImage and imageChannels.

In Mathcad this reads the blue channel of a picture file into a matrix. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files; then imageChannels(readImage(…)) gives the three channels and index 2 is the blue one.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
C≔READ_BLUE(”photo.jpg”)
C=

Reads or writes a file, so its answer depends on the file.

READ_HLS("path") Mathcad’s: refused here

Mathcad's reader of a picture as hue, lightness and saturation: recognized here, but refused; use readImage and rgbToHsv.

In Mathcad this reads a picture file as hue, lightness and saturation. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files. rgbToHsv of readImage gives hue, saturation and value, each 0 to 255, which are close to it; lightness isn't offered.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
H≔READ_HLS(”photo.jpg”)
H=

Reads or writes a file, so its answer depends on the file.

READ_HSV("path") Mathcad’s: refused here

Mathcad's reader of a picture as hue, saturation and value: recognized here, but refused; use readImage and rgbToHsv.

In Mathcad this reads a picture file as hue, saturation and value. Here it is recognized, so a worksheet that uses it opens with the name intact and goes back to Mathcad unchanged, but it doesn't run: a web page can't read files from a folder on the computer, and the line shows a note.

Load the picture with Files, then rgbToHsv of readImage gives hue, saturation and value, each 0 to 255.

Refused

  • Any call: it always gives the note about Files and doesn't read anything.
H≔READ_HSV(”photo.jpg”)
H=

Reads or writes a file, so its answer depends on the file.