Index exceeds the array element number

Hello there,
Here is the code that I wrote. It has some problem with defining 'i' as it is supposed to be the length of 'firing_rate_excel'. What part did I do wrong with it?
clear all
clc
clear filename
clear firing_rate_excel
%% Directing into PSTH excel
global Data_dir Current_dir Parent_dir
for r=3
cell_name=strcat('A',num2str(r));
histogram=strcat('B',num2str(r));
[~,Data_dir]=xlsread('bursting_all.xlsx','Sheet1',cell_name);
[~,histogram_files]=xlsread('bursting_all.xlsx','Sheet1',histogram);
Current_dir=Data_dir;
Parent_dir=Data_dir;
cd(string(Data_dir));
tempname=regexprep(histogram_files,'.mat','_');
save_filename_txt=string(strcat(Parent_dir,'\2_Sinusoids\3_PSTH\20ms\',tempname,'Averaged_Rolling_Histogram.txt'));
firing_rate_excel=[xlsread(regexprep(save_filename_txt,'txt','xlsx'),'Sheet1','A:A')];
%% Importing start and end timing
clear firing_start
clear firing_end
for l=500:length(firing_rate_excel)
logical_array=(firing_rate_excel>0)';
firing_start=strfind([0 logical_array 0],[0 1])';
firing_end=(strfind([0 logical_array 0],[1 0])-1)';
end
%% Find the minimum firing within time
for i=1:length(firing_start)
vector=firing_rate_excel(firing_start(i):firing_end(i),1);
MIN=min(vector(i),'omitnan')';
end_write_a=strcat('A',num2str(i+1));
end_write_b=strcat('B',num2str(i+1));
end_write_c=strcat('C',num2str(i+1));
xlswrite('burst_information.xlsx',MIN(i),'thresh',strcat('C2',':',end_write_c));
xlswrite('burst_information.xlsx',firing_start,'thresh',strcat('A2',':',end_write_a));
xlswrite('burst_information.xlsx',firing_end,'thresh',strcat('B2',':',end_write_b));
clear MIN
end
column_header={'firing_start','firing_end','min_value'};
%xlswrite('burst_information.xlsx',MIN,'thresh','B2');
xlswrite('burst_information.xlsx',column_header,'thresh','A1:C1');
end
disp('Done!')

 Respuesta aceptada

Amir RF
Amir RF el 10 de Dic. de 2020
Dear Yanjika,
Please check
size(firing_rate_excel)
Then you can decide the iteration variable either as size(firing_rate_excel, 1), size(firing_rate_excel, 2), ...
Best,

9 comentarios

Yanjika O
Yanjika O el 10 de Dic. de 2020
Hey, thanks for the suggestion. However, it still gives me the same error tho...
Amir RF
Amir RF el 10 de Dic. de 2020
Could you please share the value of size(firing_rate_excel)?
Yanjika O
Yanjika O el 10 de Dic. de 2020
Please replace:
for i=1:length(firing_start)
with
for i=8:length(firing_start)
use a breakpoint in the following line:
end_write_a=strcat('A',num2str(i+1));
and see the result of MIN. I guess the problem is here. The dimention of Min vector is 1 by 7 probably.
Yanjika O
Yanjika O el 10 de Dic. de 2020
it is the same
Yanjika O
Yanjika O el 10 de Dic. de 2020
I mean there is nothing has changed in here
I know it is the same. I am trying to say that the dimention of MIN vector is probably 1 by 7. In the following line
xlswrite('burst_information.xlsx',MIN(i),'thresh',strcat('C2',':',end_write_c));
you are calling MIN(8), which does not exist. That is the problem.
Yanjika O
Yanjika O el 10 de Dic. de 2020
Yep that is exactly what`s happening.
I do not know what is the purpose of this code, but maybe you can just write
xlswrite('burst_information.xlsx',MIN,'thresh',strcat('C2',':',end_write_c));
I dropped the index "i" in this line.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 10 de Dic. de 2020

Comentada:

el 10 de Dic. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by