Indexing Large Numbers of Data by Name

조회 수: 2 (최근 30일)
Sam Vellequette
Sam Vellequette 2021년 3월 13일
댓글: Sam Vellequette 2021년 3월 13일
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.

답변 (1개)

Walter Roberson
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
Walter Roberson
Walter Roberson 2021년 3월 13일
Sorry, fixed again.
Sam Vellequette
Sam Vellequette 2021년 3월 13일
Hey, I did one quick last revision to attempt to condense it. Here's the final product. Thank you again!
dinfo = dir('TestRun*.xlsx');
numfiles = length(dinfo);
all_data(numfiles,1) = struct(); %preinitialize struct
for K = 1 : numfiles
filenames = {dinfo(K).name};
[~, basename, ~] = fileparts(char(filenames));
data = readmatrix(char(filenames));
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by