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!