While shell variables can't typically contain binary data, you can save their values to a file; the simplest example would be:
seg=$(seq 1 100)
printf '%s\
' "$seg" 000000001.mat
Above, I'm populating the `seg` variable with the output from a command (the numeric sequence 1..100), then asking the `printf` command to print that string, followed by a newline. The shell redirects that value into the named file.