for loop through matrix index
Mostra commenti meno recenti
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 Commenti
KALYAN ACHARJYA
il 28 Ott 2022
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
il 28 Ott 2022
David Hill
il 28 Ott 2022
Is simple example of inputs and expected output would be helpful. I am not understanding your description.
Enzo
il 28 Ott 2022
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!