我正在使用此代码在A(i).data
. 我正在做的是导入一个txt,手动输入不同范围的中心( ),为范围(和)ppmdata
设置极值,找到它们的索引(收集在数组g中)然后使用索引查找中的值。emax
emin
A(i).data
代码工作正常,直到我添加(减去)到 emax(和 emin)的数字等于或小于 0.01。当更大时,matlab 给我一个错误:
Error in ==> NMR at 27
Massimo=max(A(i).data(g(1,1):g(m3,1),2));
打开 g,我并不是说元素 g(m3,1) 完全超出比例,甚至不对应于 A(i).data 的值(如果我检查该索引,我得到一个空单元格)。如果我使用
Massimo=max(A(i).data(g(1,1):g(m3-1,1),2));
它完美地工作。
% % Call all txt file
[filename, pathname] = uigetfile('*.txt','Select the Excel file:', 'MultiSelect','on');
%% Import all file
[m1,n1]=size(filename);
A(1:n1)=struct('data',zeros(),'textdata',zeros());
for i=1:n1
nomefile= fullfile(pathname,filename{1,i});
A(i)=importdata(nomefile);
end
%% ask which X values to monitor
prompt = {'Insert PPM values you want to monitor:'};
dlg_title = 'PPM';
num_lines = 1;
def = {'0.78,1.00,1.18'};
ppminput = inputdlg(prompt,dlg_title,num_lines,def);
ppmdata = str2num(ppminput{:});
%% Found the maxima for each X value in a range emin<X<emax
g=zeros();
[m2,n2]=size(ppmdata);
result=struct('data',zeros(),'name','', 'columnheading','');
for i=1:n1 % ciclo per mettere il nome
for j=1:n2 %ciclo per mettere il dato
emax=(ppmdata(1,j)+0.1;
emin=(ppmdata(1,j)-0.1);
g=find((A(i).data<emax) & (A(i).data>emin));
[m3,n3]=size(g);
Massimo=max(A(i).data(g(1,1):g(m3,1),2));
if Massimo<0
result.data(i,j)=0;
result.columnheading{1,j}=['PPM:', ' ', num2str(ppmdata(1,j))];
else
result.data(i,j)=Massimo;
result.columnheading{1,j}=['PPM:', ' ', num2str(ppmdata(1,j))];
end
end
result.name{i,1}=A(i).textdata(19,1);
end
for i=1:n1
for j=1:n2 %ciclo per mettere il dato
result.data(i,n2+j)=((result.data(i,j)/sum(result.data(i,1:n2)))*100);
result.columnheading{1,j+n2}=['Percentage:', ' ', num2str(ppmdata(1,j))];
end
end