How do I open a .raw file so that it can be viewed as a table?
52 views (last 30 days)
Show older comments
Cole Garabed
on 14 Jan 2022
Commented: Cris LaPierre
on 16 Feb 2024
I have this .raw file that I would like to open in as a table so I can then further process the data. I currently have to open the file using excel and then import the excel file as a table into matlab, but I want to cut out that step. (Also, I have code written to clean up the table once it's in matlab, so I'm not worried if the import has a bunch of NaN values). I can't attach the .raw file becase matlab doesn't support the format so I'm attaching the excel file.
%% Import data and convert excel file to a struct
% Input the .xlsx file in the function below
T = readtable('OS-1-69-B1-HT.is_comp.xlsx');
% Rectify and organize data
row_valid = ~reshape(ismissing(T(:,1)), 1 , []);
starts = strfind([false row_valid], [false true ]);
stops = strfind([row_valid, false], [true false]);
sub_tables = arrayfun(@(B,E) T(B:E,:), starts, stops, 'uniform', 0);
% Convert the table to a struct
Data = struct();
for i = 1:length(sub_tables)
Data.(sprintf('Specimen%d',i)) = sub_tables{i};
end
3 Comments
Accepted Answer
Cris LaPierre
on 15 Jan 2022
Edited: Cris LaPierre
on 17 Jan 2022
Consider starting with this:
T = readtable("OS-1-69-B1-HT.is_comp.raw",'Delimiter',{'"',','},...
'FileType','text','numHeaderLines',94)
Add your code, and it appears the result is the same (though not checked exhaustively)
3 Comments
Charles
on 16 Feb 2024
How would you go about modifying this code to read through a folder of raw data and output spreadsheets for each file?
This code works well for individual files, but I need to automate the process for new data, so typing the individual file names is not efficient.
Cris LaPierre
on 16 Feb 2024
Do you need a separate spreadsheet for each file? If so capture the file names in an array (I'd use dir), then place the code inside a for loop so that it runs the code for each file.
In both cases, use writetable to write the data to a spreadsheet.
More Answers (0)
See Also
Categories
Find more on Tables 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!