Index exceeds the array element number
1 view (last 30 days)
Show older comments
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!')
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/456824/image.png)
0 Comments
Accepted Answer
Amir RF
on 10 Dec 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 Comments
Amir RF
on 10 Dec 2020
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.
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!