Importing data from a .prc (unrecognised) filetype using variable names
Show older comments
Hi there, I am trying to import a selection of data from many files of the same type (.prc), but I would only like to import the data under select heading names from these files.
I have used the import tool to generate a script to start this off, my problem is that this assumes a fixed number of headings/variables for each file that I then use this on. I am iterating through many of these files, some of them may have the variables that I want as defined in "Var Names", and some will not. When I run this in a loop which goes through the folders, some of the outputs may be correct which match the parameters, but if the number of params in file 'i' does not match what is specified here. I end up with data that is shifted left/right in in thet component of my final structure, so not in the right place/heading and not reliable to use.
opts = delimitedTextImportOptions("NumVariables", 70); % Number of headings, specified fixed
% Specify range and delimiter
opts.DataLines = [305, Inf]; % Jump to Data after [Data+Units]
opts.Delimiter = "\t";
% Specify column names and types
opts.VariableNames = ["Var Names"];
opts.VariableTypes = ["Data Type (all double)"];
% Specify file level properties
opts.ExtraColumnsRule = "ignore";
opts.EmptyLineRule = "read";
opts.ConsecutiveDelimitersRule = "join";
% Specify variable properties
opts = setvaropts(opts, ["Var Name Opts"]);
opts = setvaropts(opts, ["Var Name Opts"], "EmptyFieldRule", "auto");
opts = setvaropts(opts, "Var Name Opts", "ThousandsSeparator", ",");
% Import the data
data.(folderlist(i))=readtable(['Data Folder Path',folderlist(i).name], opts);
%% Clear temporary variables
clear opts
end
I would preferably like to be able to use the variable names I have specifed to search for exact matches, but I'm not sure how to go about it with this setup/file type. The variables/headers that I want exist in each of the files, just often in different column locations.
I would like to try to avoid changing everything over to a known filetype (e.g. excel) and then using a srtcmp to find the right headers, but I am not sure of a better way to do this that could use less time/resource.
If anyone familiar with the import tool is able to help, then that would e great!
Thanks,
C.
Accepted Answer
More Answers (0)
Categories
Find more on Workspace Variables and MAT 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!