- specify the FORMAT option (using TEXTSCAN() formats)
- use SETVARTYPE() before calling READTABLE().
Can I make readtable to be of single precision for numeric values?
6 views (last 30 days)
Show older comments
Hello everybody,
I am running an extensive for-loop inside a while-loop that at each respective iteration optimizes a different problem and pass information between each optimization. Given that I want to make it faster and consume less memory, I have been trying different approaches and want the optimization process to use single-precision variables as much as possible.
However, an important chunk of variables are created when the code reads information from external files using readtable, and I want to make sure that the numeric values or numeric variables are of single precision.
Have not been able to find some information about it in the documentation. So, my question is: ¿is there a way for me to make numeric variables/numeric input of readtable to be of single precison?
Thanks everybody for their time.
0 Comments
Accepted Answer
Stephen23
on 2 Jan 2023
Edited: Stephen23
on 2 Jan 2023
"¿is there a way for me to make numeric variables/numeric input of readtable to be of single precison?"
Two approaches to specify the class of numeric data when importing numeric data:
Method 1: FORMAT option:
The READTABLE documentation explains the FORMAT option in the text file options section:
The format that used by TEXTSCAN():
fnm = 'test.txt';
tb1 = readtable(fnm, 'Format','%f32%f%f') % first column SINGLE
class(tb1.X)
Method 2: SETVARTYPE() function:
The READTABLE() documentation describes the import options object here:
The supporting functions are:
obj = detectImportOptions(fnm);
obj = setvartype(obj,'X','single'); % first column SINGLE
tb2 = readtable(fnm, obj)
class(tb2.X)
More Answers (0)
See Also
Categories
Find more on Standard File Formats in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!