필터 지우기
필터 지우기

How do I filter time data from excel columns, where the values are numerical and the columns are character named?

조회 수: 2 (최근 30일)
Hello,
I'm trying to create a code that will filter eyelink fixations (labeled IA_FIRST_SACCADE_START_TIME) that took place before the stimulus onset (time). I've tried creating a variable that will only use the columns I need (6 and 8) like so
fixation = raw(6:8)
but it only outputs an array of 3 12s like so
[{12} {12} {12}]
I also tried creating a for loop as
for (i=='time'> 0) in raw %there was a stimulus present
if (i== 'time'> 0)
for ('IA_FIRST_SACCADE_START_TIME'> 'time')
add('IA_FIRST_SACCADE_START_TIME', fixations)
end
end
but I get the error for invalid use of operator
Finally, I've tried creating an indexed variable like
data=raw('time'>=0 && ('FIRST_SACCADE_START_TIME'>='time'==||));
but that comes out with another invalid use of operator error too
What should I do to make this work? Any help at all would be appreciated

채택된 답변

Simon Chan
Simon Chan 2021년 7월 16일
편집: Simon Chan 2021년 7월 16일
Better to look at the usage of those data import function used in MATLAB.
I use readcell in this case.
rawdata=readcell('RES_IAS (1).xlsx'); % Use readcell to read all data
data=rawdata(:,6:8); % Extract 6th to 8th column
header = rawdata(1,6:8); % Extract the headers
Start_time = cell2mat(data(2:end,1)); % Convert to a matrix for data in column 6
time = cell2mat(data(2:end,3)); % Convert to a matrix for data in column 8
idx1=Start_time>time; % Find index for Start_time > time
result = [Start_time(idx1) time(idx1)]; % This is the result you may want in matrix form
plot(Start_time(idx1)) % Plot the Start_time
hold on
plot(time(idx1)) % Plot the time
legend(header{1},header{3}) % Legend
  댓글 수: 3
Simon Chan
Simon Chan 2021년 7월 22일
The function readcell on my previous code would read the header on the first row, and data starts from the second row.
If you use readtable, data will appear in the 1st row instead. On the other hand, the headers are stored in its Properties, hence you cannot just retrieve the first row as the header.
The following is for your reference if you would like to use function readtable:
rawdata = readtable('RES_IAS (1).xlsx');
Start_time = rawdata.IA_FIRST_SACCADE_START_TIME;
time = rawdata.time;
idx1 = Start_time>time;
result = [Start_time(idx1) time(idx1)];
plot(Start_time(idx1))
hold on
plot(time(idx1))
legend(rawdata.Properties.VariableDescriptions{6},rawdata.Properties.VariableDescriptions{8});
Peter Perkins
Peter Perkins 2021년 7월 27일
readcell has its purposes, but the right thing to use is MUCH more likely to be readtable.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Timetables에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by