for loop through matrix index
이전 댓글 표시
Hello everyone,
a very basic issue which is causing me a lot of pain (drama queen mode ON).
How to iterate on operation using a matrix index, currently stored in variable "lc" (which has all the rows index I want to use) and I would like to use these rows index in the new_ch variable.
In practice, I would like to use the index stored in "lc" as a index localization for the variables stored in the rows (the rows from 1 to 32) in "new_ch" variable.
using these lines of code (which you will find in the "big" code below), I obtain in variable S exactly what I am looking for, but it only work out one time (of course)
% S = new_ch((lc-pre_stim):(lc+(post_stim-1)),:);
% S
The final loop is my attempt, which is not working. the error code:
Index in position 1 is invalid. Array indices must be positive integers or logical values.
Error in extract_threshold_ADC (line 32)
V = i((new_ch-pre_stim):(new_ch+(post_stim-1)),:);
if you are able to go through all this process without using the for loop feel free to make any suggestion.
If needed, please download the file following these link: actual data being used
Thanks so much in advance, any tips will be very appreciated
adc_chan = 3; % to be set according to the ADC channels being used
load Open_Ephys_2022-10-19_14-10-17_st1.mat ADC CH;
new_ch = horzcat(CH, ADC(:,adc_chan));
%% Step 2: define a threshold for channel 35 (ADC channel) values and retain all the rows from
thr = 4; % determine the minimun threshold amplitude for stimulation being applied
idx = new_ch(:,33)>thr;
values_to_keep = new_ch(idx,:);
%% find peak in column 33 (only spot the rising edge. see lc to index location)
fs = 10000; % sampling frequency
[pk,lc] = findpeaks(new_ch(:,33), MinPeakHeight=thr);
%% define epoch features and extract epochs
pre_stim = 5000; % period pre-stimulus to retain
post_stim = 15000; % period post-stimulus to retain
% S = new_ch((lc-pre_stim):(lc+(post_stim-1)),:);
% S
for i = 1:length(lc)
V = i((new_ch-pre_stim):(new_ch+(post_stim-1)),:);
end
댓글 수: 4
KALYAN ACHARJYA
2022년 10월 28일
Pls note, do you calculate the indices for i within the bracket?
V = i((new_ch-pre_stim):(new_ch+(post_stim-1)),:);
The problem seems simple, however it would be easier to check if you can attach the file.
Enzo
2022년 10월 28일
David Hill
2022년 10월 28일
Is simple example of inputs and expected output would be helpful. I am not understanding your description.
Enzo
2022년 10월 28일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!