Indexing Large Numbers of Data by Name
조회 수: 2 (최근 30일)
이전 댓글 표시
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
답변 (1개)
Walter Roberson
2021년 3월 13일
편집: Walter Roberson
2021년 3월 13일
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Structures에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!