Read specific hex data in CSV file
이전 댓글 표시
I've looked through the posts on StackOverflow and on MATLAB Answers and can't seem to find the answer I am looking for. I have a large CSV file (450 MB) with hex data that looks like this:
63C000CF,6000002F,603000AF,6000C06F,617300EF,6C7C001F,6000009F,0%,63C000CF...
That is a very truncated example, but basically I have approximately 78 different hex values separated by commas, then there will be the '0%', then 78 more hex values. This will continue for a very long time. I've been using textscan like this:
data = textscan(fid, '%s', 1, 'delimiter', '%');
data = textscan(data{1}{1}, '%s', 'delimiter', ',');
data = data{1};
count = size(data);
outstring = ['%', sprintf('\n')];
for idx = 1:count(1)
string = data{idx};
stringSize = size(string);
if stringSize(2) > 1
outstring = [outstring, string, sprintf('\n')];
end
end
fprintf(output_fid, '%s', outstring)
This allowed me to format the csv file in a way to which I could use fgetl() to analyze whether or not I was looking at the data I needed. Because the data repeats itself, I can use fseek() to jump to the next occurrence before calling fgetl() again.
What I need is a way to skip to the ending. I want to just be able to use something like fgetl() but have it only return the first hex value it encounters. I will know how many bytes to shift through the file. Then I need to make sure I can read other hex values. Is what I'm asking possible? My code using textscan above takes far too long on a csv file that is 90 MB let alone 450 MB.
댓글 수: 6
dpb
2014년 6월 4일
... have approximately 78 different hex values separated by commas, then there will be the '0%', then 78 more hex values
The "approximately" in there is a kicker--is the spacing consistent within a file but different files may have some other number or within a file? Could make all the difference...
Also, what, specifically, are you trying to return--a set of values a fixed offset apart or what?
Awaiting those answer, you may want to look at memmapfile
Adam Kaas
2014년 6월 4일
dpb
2014년 6월 4일
Still not clear...which, precisely are the values you're after? How do you define those of interest? Need the logic behind the process of retrieval, not the rationale of what to do with them when get 'em or how/where they came from...
Adam Kaas
2014년 6월 4일
dpb
2014년 6월 4일
I know you know what you're after, but we can only go by what is revealed here. Don't be so terse; over-explain rather than under-...
...Each set of hex values represents a label
What's a "set" in this context? A single value or all the values of a given offset relative to the beginning/the flag value? Or is it the entire group between the flag values?
Is "one label" above a single 16-bit hex value or again all of the same offset or the group at a the location of the indicated flag value? Have to have a precise definition of what it really is you're after.
How is/are the one(s) wanted identified?
What is the function of the indicator
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Text Data Preparation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!