Index exceeds the array element number
조회 수: 3 (최근 30일)
이전 댓글 표시
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!')
댓글 수: 0
채택된 답변
Amir RF
2020년 12월 10일
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
Amir RF
2020년 12월 10일
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.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!