What's the simplest way to read data from a text file into a 1xN integer in MatLab
What's the simplest way to read datas from a text file into a 1xN integer in MatLab?
I'm writing the data into a text file from a Java program, which means it is highly flexible how 开发者_运维技巧the text file could look like. These data are to be plotted (pdf or cdf).
The file could be quite large, millions of integers. It shouldn't matter I guess.
If it's a text file (not a binary file), you can probably just use the LOAD command:
data = load('file.txt','-ascii'); %# Load the data
data = data(:).'; %'# Format the data into a row vector
I assume your data file could have one value per row or one long row with values separated by spaces, so the (:).'
operation (a colon reshape plus a transpose) ensures that no matter which one it is you will get a 1-by-N result for data
.
精彩评论