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에서 Data Import and Analysis에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!