Access and extract table array using for loop
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have this table
tt = edfread('example.edf')
and I need to extract (or access) the data using "for loop". For example, from "ECG", we can extract the data from 0 sec, 10 sec, 20 sec, etc. without typing the code one-by-one manually. What should I do? Thank you.
0 comentarios
Respuestas (3)
VBBV
el 13 de Abr. de 2023
Editada: VBBV
el 13 de Abr. de 2023
tt = edfread('example.edf')
tt = timetable2table(tt);
tt.Properties.VariableNames = {'Time','ECG','EEG2'};
for k = 1:length(tt.ECG)
fprintf('ECG Data at %s is\n',[tt.Time(k)])
cell2mat(tt.ECG(k))
end
4 comentarios
VBBV
el 13 de Abr. de 2023
Editada: VBBV
el 14 de Abr. de 2023
You can access all table data without inputting one by one as shown below
tt = edfread('example.edf');
tt = timetable2table(tt);
tt.Properties.VariableNames = {'Time','ECG1','ECG2'};
%%% for large number of variables %%%
% fprintf(repmat('%s Data',1,100) \n', string(tt.Properties.VariableNames(2:end)))
fprintf('%s Data %s Data \n', string(tt.Properties.VariableNames(2:end)))
for k = 1:length(tt.ECG1)
fprintf('at %s is\n',tt.Time(k))
% access all data from table without inputting one by one
Data = cell2mat(table2cell(tt(k,2:end)))
end
Ran Yang
el 13 de Abr. de 2023
You can call everything in the ECG column using {:} and then concatenate it. Note the curly brackets.
data = cat(1, tt.ECG{:});
You can also specify a subset of rows (e.g. 0 sec, 20 sec, 40 sec) in the same way you would index a regular array.
subdata = cat(1, tt.ECG{1:2:5});
Stephen23
el 13 de Abr. de 2023
"I need to extract (or access) the data using "for loop". For example, from "ECG", we can extract the data from 0 sec, 10 sec, 20 sec, etc. without typing the code one-by-one manually."
You can use curly-brace indexing:
Note that the example numeric data is nested in cell arrays in a table:
T = edfread('example.edf')
for ii = 1:height(T)
for jj = 1:width(T)
V = T{ii,jj}{:}
end
end
0 comentarios
Ver también
Categorías
Más información sobre Data Import and Analysis en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!