Access and extract table array using for loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(3 个)
VBBV
2023-4-13
编辑:VBBV
2023-4-13
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 个评论
VBBV
2023-4-13
编辑:VBBV
2023-4-14
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
2023-4-13
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
2023-4-13
"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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!