In Matlab, you can use the textscan
function to read a file. It reads data from a file into an array or cell array. Here's an example code:
main.m127 chars4 lines
The above code will read a file named filename.txt
that has two columns with strings and two columns with floating point numbers separated by spaces, and store the data in a cell array C
.
You can customize the function by changing the parameters to match the format of your data. The second parameter in textscan
specifies the data format ('%s %f %f'
in the example) and must match the data format in the file you're reading.
For more information, see the Matlab documentation: https://www.mathworks.com/help/matlab/ref/textscan.html
gistlibby LogSnag