Index exceeds the array element number
1 回表示 (過去 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 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!