.MAT FILES AND WRITING CODE TO ANALYSE THE .MAT FILES

45 visualizaciones (últimos 30 días)
caroline bourn
caroline bourn el 11 de Mzo. de 2021
Comentada: caroline bourn el 22 de Mzo. de 2021
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;
while(fin)
% make seperate files for the tests.
for i=1:length(pts)
matrix = [x(next:pts(i,:)), y(next:pts(i,:)), test_cond(next:pts(i,:))];
filename = sprintf('%s_%d','test',i);
save(filename, 'matrix')
next = pts(i);
end
if pts(i) == length(pts)
fin = 0;
end
return
end
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.
  2 comentarios
Athul Prakash
Athul Prakash el 16 de Mzo. de 2021
Hi Caroline, quick tip..
When trying to get help on this platform, it helps to ask a specific question and leave out details that are not needed. If the question can be understood by a third party in quick time, you are far more likely to receive a response. Also, please refrain from capitalizing the headline or using imperative language in the question, as that is something most people in the community try to avoid and hence your question may go unanswered.
I found the following page to be a good guideline when I'm on this platform:-
caroline bourn
caroline bourn el 16 de Mzo. de 2021
thanks for the tip :) i'll keep it in mind :)!!

Iniciar sesión para comentar.

Respuesta aceptada

Athul Prakash
Athul Prakash el 16 de Mzo. de 2021
Hi Caroline,
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
start=1
for i=1:length(seps)
% 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;
end
% 'tests' is a (numTests x 1) dimensional array of structures, each
% having one field 'data'
save('test.mat', tests);
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!
  1 comentario
caroline bourn
caroline bourn el 22 de Mzo. de 2021
hey thanks for your comment! i managed to find a way to do it.
i used cells and then concatenated. my supervisor informed me it would be the best approach for my situation.
i did try your way and it was very useful! thank you

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Structures en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by