Indexing Large Numbers of Data by Name
6 views (last 30 days)
Show older comments
Hi! So I'm trying to write a software for gathering data from tensile tests. I'm fine writing the code for each individual test results, but I'm struggling to find a way to index large amounts of data. Basically, I'm going to recieve an xlsx file for each test named TestRun2_1_29_2021 or TestRun3_1_29_2021, and I will have somewhere around 150 of these tests to run. Each xlsx file contains two column vectors- one for stress, and one for strain. I currently am trying to use a structure array to save the vectors, but I don't know how to navigate through the array.
%First I'm loading the full results, which consists of (for this brief example) 7 different tests
data=load('TensionTest1_19_21.mat');
% Ideally I could navigate through this structure with some simple for loop like
for i=1:length(data)
plot(dataAinT(i),dataEssT(i))
end
%etc but I don't know how to create indexable variables like that.
If anyone has any ideas how to load ~150 tests through a for loop and just have some loop run all the calculations, I'd really appreciate it.
Again, my primary concern is I don't have any clear understanding how to create a structure of indexable vectors, such as the structure array I have now.
0 Comments
Answers (1)
Walter Roberson
on 13 Mar 2021
Edited: Walter Roberson
on 13 Mar 2021
dinfo = dir('TestRun*.xlsx');
filenames = {dinfo(K).name};
numfiles = length(filenames);
all_data(numfiles,1) = struct(); %preinitialize struct
for K = 1 : numfiles
thisfile = filenames{K};
[~, basename, ~] = fileparts(thisfile);
data = readmatrix(thisfile);
all_data(K).dataAinT = data(:,1);
all_data(K).dataEssT = data(:,2);
all_data(K).name = basename;
end
for K = 1 : numfiles
plot(all_data(K).dataAinT, all_data(K).dataEssT, 'DisplayName', all_data(K).name);
hold on
end
legend show
5 Comments
See Also
Categories
Find more on Structures 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!