Replacing numbers in the matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I have matrices with logfile and data. The first 5 columns is the log fille that logs stimuli representation in time (an example, attached below ). The rows are time and the columns are events. The first column logs stimuli id in time. (No stimulus =0, stimulus : 1 2 3 4 5 or 6) The second column logs the trial stages(1=pre stimulus, 2=stimulus, 3=poststimulus interval); However stimulus durations are not exactly the same for all stimuli. Some have 40 rows some 41. I need make all stimuli the same length by adding or removing stimuli ids at the end of the stimulus without adding any new rows to the matrix. For example, make all stimuli to given desiered duration 40 rows by edding or removing missing or additional stimulus ids at the end of the stimulus in colomn 1 and column 2 Could anyone help with this?
댓글 수: 2
Matt J
2024년 1월 21일
편집: Matt J
2024년 1월 21일
I need make all stimuli the same length by adding or removing stimuli ids at the end of the stimulus without adding any new rows to the matrix.
Does that mean the number of rows has to remain the same as the original number of rows? That is impossible, because the number of rows in the given .xlsx file is the prime number 9371. There is no way, therefore, that the number of rows can be decomposed into an even multiple of a common stimuli duration.
채택된 답변
Voss
2024년 1월 21일
"I just need to replace redundant Ids numbers with 0 in column1 or with 3 in column2 to reach desireble stimulus length"
filename = 'data _matrix (1).xlsx';
% read the data
data = readmatrix(filename);
% find where stimuli start and end
d = diff(data(:,1));
stimulus_start_idx = find(d > 0)+1;
stimulus_end_idx = find(d < 0);
% length (number of rows of data) of each stimulus
stimulus_length = stimulus_end_idx-stimulus_start_idx+1;
% number of stimuli
N_stimulus = numel(stimulus_length);
% number of rows to alter from each stimulus
n_rows_to_alter = stimulus_length-min(stimulus_length);
% prepare to mark some rows for alteration; initially none are marked
alter_row = false(size(data,1),1);
% loop over all stimuli
for ii = 1:N_stimulus
% for stimulus ii, mark the last n_rows_to_alter(ii) rows for alteration
alter_row(stimulus_end_idx(ii)+(-n_rows_to_alter(ii)+1:0)) = true;
end
% alter the rows
data(alter_row,1) = 0;
data(alter_row,2) = 3;
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!