Converting numeric strings in cell to number for very large dataset
Show older comments
I have read this post which does something similar: https://uk.mathworks.com/matlabcentral/answers/375506-coverting-numeric-strings-in-cell-to-numbers
However I wanted to know if there is a more efficient way to do this as my data-set is very large. My dataset contains both text and numbers I what to convert numbers only to number format.
load('Data.mat')
tic
Qnum=str2double(Q);
toc
This code takes about 124 seconds to run
I have tried preallocating Qnum but the run time is about the same:
Qnum=zeros(length(Q),1);
6 Comments
Peter Mills
on 10 Jan 2018
Edited: Peter Mills
on 10 Jan 2018
"Sorry the full file is 329MB so is too large to attach."
You do not need to give us the complete file: all we need is enough so that we have a representative file to work with: in particular the header lines and a megabyte or so of data.
The approach in your question (importing as strings in a cell array then using str2double) is very inefficient. If you really want help with this then please give us a representative file to work with and upload it here: create a new comment, and then click the paperclip button.
Peter Mills
on 10 Jan 2018
Edited: Peter Mills
on 10 Jan 2018
Stephen23
on 10 Jan 2018
"What is the best way to extract part of the file to post here?"
Use Notepad++.
Peter Mills
on 11 Jan 2018
Peter Mills
on 11 Jan 2018
Accepted Answer
More Answers (0)
Categories
Find more on Text Files 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!