.MAT FILES AND WRITING CODE TO ANALYSE THE .MAT FILES
조회 수: 8(최근 30일)
Hello everyone. i am going to try give you as much information as possible. i know it may seem like a simple question but i am ripping my hair out.
ok so my original txt file has over 3000 rows of data and 5 columns.i have written a code that goes through the time (column 2) and identifies a change. That change in time corresponds to the start of a new test. For the original text file i found i have 3 tests, hence, 3 .mat files that i have saved using the following script. Each .mat file has 3 columns and multiple rows and each .mat file corresponds to a seperate test (like i mentioned). the columns are x,y, test condition 1 -18 etc.
pts = findchangepts(data(:,2), 'Statistic', 'linear', 'MinThreshold',100)
pts(end+1) = finalrow;
num_step = data(:,1)
x = data(:,4);
y = data(:,5);
fin = 1;
next = 1;
% make seperate files for the tests.
matrix = [x(next:pts(i,:)), y(next:pts(i,:)), test_cond(next:pts(i,:))];
filename = sprintf('%s_%d','test',i);
next = pts(i);
if pts(i) == length(pts)
fin = 0;
NOW i want to write code to do whatever it is i want it to do and i want it to do it to each mat file.
i.e. go through each test and find all the zeroes, save those in a seperate file blah blah blah.
i know i have to use a loop but some advice as to the best and most efficent way to execute this would be great.
my coding is not fantastic so please, if you dont have anything useful or nice to contribute dont do it at all. thanks.
Athul Prakash 2021년 3월 16일
You may consider using struct arrays to group your data, and save everything to one file as a simplification.
% Consider one struct for each 'test' that you mention, each struct having one field say 'data'\
tests = struct() % initialize an empty 1x1 struct
% variable 'seps' - separators, ending indices of each
% variable 'data' - 2D array to split up row-wise
% add the data for i-th test to the field called 'data' in i-th structure
tests(i).data = data(start:seps(i), :);
start = seps(i)+1;
% 'tests' is a (numTests x 1) dimensional array of structures, each
% having one field 'data'
You may read the following documentation to get a grip of MATLAB structures
It's like a structure in C, where you can group data in different 'fields' (such as 'data' above) and access using dot notation.
But MATLAB has structure arrays, which means you can group many structures with same fields into an array of any shape.
Hope it helps!