Index exceeds the number of array elements (0). Error in TPA (line 32) time_orig = time_orig - time_orig(1);can any one solve this

2 vues (au cours des 30 derniers jours)
Hello there am facing problem in this. i can run one text file which has 1-1603 numbers and this one i have 1-3504 numbers showing errors. how to fix it.
clear all;
clc;
close all;
filename = 'text2.xlsx';
sheet = 1;
start = '1';
end1 = '3504';
forceRange = ['B' start ':B' end1];
disprange = ['C' start ':C' end1];
timerange = ['A' start ':A' end1];
force_orig = xlsread(filename, sheet, forceRange);
disp_orig = xlsread(filename, sheet, disprange);
time_orig = xlsread(filename, sheet, timerange);
compute = 1;
time_interval = 0.1;
specimen_type = 1;
specimen_dia = 10;
specimen_height = 10;
specimen_area = pi*(specimen_dia/2)^2;
endcount = 4;
mean_range = 10;
tol_factor = 2;
[inum, jnum] = size(time_orig);
startpt = 1;
endpt = inum;
time_orig = time_orig - time_orig(1);
time_end = round(max(time_orig));
time = 0:time_interval:time_end;
time = time';
disp = interp1(time_orig, disp_orig, time); % Error fixed
force = interp1(time_orig, force_orig, time);
[isize, jsize] = size(time);
x_halfspan = round(isize/2);
mean_force_level = mean(force(x_halfspan-mean_range:x_halfspan+mean_range));
force = force-mean_force_level; % offset zero force level
tol_force_level_max = max(force(x_halfspan-mean_range:x_halfspan+mean_range))*tol_factor;
tol_force_level_min = min(force(x_halfspan-mean_range:x_halfspan+mean_range))*tol_factor;
point1=1;
point2=1;
point3=1;
point4=1;
point5=1;
point6=1;
point7=1;
point8=1;
point3c=1;
point1 = 1;
[dispmax1 point3c] = max(disp(1:x_halfspan));
[dispmax2 point7temp] = max(disp(x_halfspan+1:isize));
point7 = point7temp+x_halfspan;
[Hardness point3] = max(force(1:point3c));
counter = 0;
point2 = 1;
for i = 1:point3
[force_p2 ip2] = max(force(1:i));
if point2==ip2
counter = counter+1;
else
point2 = ip2;
counter = 0;
end
if counter == endcount
break
end
end
point4 = point3c;
for i = point3c:x_halfspan
if force(i)<=tol_force_level_max
point4 = i;
break
end
end
point5 = point4+20;
point6 = point7;
for i=point7:-1:x_halfspan
if force(i)<=tol_force_level_max
point6 = i;
break
end
end
point8 = point7;
for i=point7:isize
if force(i)<=tol_force_level_max
point8 = i;
break
end
end
dispscale =1; %25
%for adjusting the space of texts in the figure
xstep = 40;%120
ystep = 5;
points = [point1 point2 point3 point4 point5 point6 point7 point8 point3c];
apt_points = [startpt endpt points];
figure;
subplot(2,1,1),plot(time,disp,'r','LineWidth',1.5),xlabel('Time (s)'), ylabel('displacement (mm)'), grid on;
text (time(points(1)),disp(points(1)),'x point1','Fontsize',14);
text (time(points(2)),disp(points(2)),'x point2','Fontsize',14);
text (time(points(3)),disp(points(3)),'x point3','Fontsize',14);
text (time(points(4)),disp(points(4)),'x point4','Fontsize',14);
text (time(points(5)),disp(points(5)),'x point5','Fontsize',14);
text (time(points(6)),disp(points(6)),'x point6','Fontsize',14);
text (time(points(7)),disp(points(7)),'x point7','Fontsize',14);
text (time(points(8)),disp(points(8)),'x point8','Fontsize',14);
text (time(points(9)),disp(points(9)),'x point3c','Fontsize',14);
subplot(2,1,2),plot(time,force,'LineWidth',1.5),xlabel('Time (s)'), ylabel('force (N)'), grid on;
text (time(points(1)),force(points(1)),'x point1','Fontsize',14);
text (time(points(2)),force(points(2)),'x point2 Fracturability','Fontsize',14);
text (time(points(3)),force(points(3)),'x point3 Hardness','Fontsize',14);
text (time(points(4)),force(points(4)),'x point4','Fontsize',14);
text (time(points(5)),force(points(5)),'x point5','Fontsize',14);
text (time(points(6)),force(points(6)),'x point6','Fontsize',14);
text (time(points(7)),force(points(7)),'x point7','Fontsize',14);
text (time(points(8)),force(points(8)),'x point8','Fontsize',14);
text (time(points(9)),force(points(9)),'x point3c','Fontsize',14);
figure;
plot(force,'LineWidth',1.5);
hold on;
grid on;
plot(disp,'r','LineWidth',1.5);
text (points(1),force(points(1)),'x point1','Fontsize',14);
text (points(2),force(points(2)),'x point2 Fracturability','Fontsize',14);
text (points(3),force(points(3)),'x point3 Hardness','Fontsize',14);
text (points(4),force(points(4)),'x point4','Fontsize',14);
text (points(5),force(points(5)),'x point5','Fontsize',14);
text (points(6),force(points(6)),'x point6','Fontsize',14);
text (points(7),force(points(7)),'x point7','Fontsize',14);
text (points(8),force(points(8)),'x point8','Fontsize',14);
text (points(9),disp(points(9))*dispscale,'x point3c','Fontsize',14);
if compute == 1
% TPA_fun_5
length1 = time(points(9))-time(points(1));
length2 = time(points(7))-time(points(6));
dispdiff4 = disp(points(1)+1:points(9)+1)-disp(points(1):points(9));
area4 = sum(force(points(1):points(9)).*dispdiff4);
dispdiff5 = disp(points(9)+1:points(4)+1)-disp(points(9):points(4));
area5 = -sum(force(points(9):points(4)).*dispdiff5); % displacement is decreasing so we need the negative sign
area1 = area4+area5;
dispdiff3 = disp(points(4)+1:points(5)+1)-disp(points(4):points(5));
area3 = sum(force(points(4):points(5)).*dispdiff3); % displacement is decreasing and force is negative
dispdiff2part1 = disp(points(6)+1:points(7)+1)-disp(points(6):points(7));
area2part1 = sum(force(points(6):points(7)).*dispdiff2part1);
dispdiff2part2 = disp(points(7)+1:points(8)+1)-disp(points(7):points(8));
area2part2 = -sum(force(points(7):points(8)).*dispdiff2part2); % displacement is decreasing
area2 = area2part1+area2part2;
Hardness = force(points(3));
Fracturability = force(points(2));
Cohesiveness = area2/area1;
Springiness = length2/length1;
Gumminess = Hardness*Cohesiveness;
Chewiness = Gumminess*Springiness;
Resilience = area5/area4;
tt = points(5)+xstep;
text (tt,force(points(3))*dispscale,['Hardness= ' num2str(Hardness)],'Fontsize',14);
text (tt,force(points(3))*dispscale-ystep,['Fracturability = ' num2str(Fracturability)],'Fontsize',14);
text (tt,force(points(3))*dispscale-2*ystep,['Cohesiveness = ' num2str(Cohesiveness)],'Fontsize',14);
text (tt,force(points(3))*dispscale-3*ystep,['Springiness = ' num2str(Springiness)],'Fontsize',14);
text (tt,force(points(3))*dispscale-4*ystep,['Gumminess = ' num2str(Gumminess)],'Fontsize',14);
text (tt,force(points(3))*dispscale-5*ystep,['Chewiness = ' num2str(Chewiness)],'Fontsize',14);
text (tt,force(points(3))*dispscale-6*ystep,['Resilience = ' num2str(Resilience)],'Fontsize',14);
[isize, ~] = size(time);
TPAoutputtime = time(point1:isize)-time(point1);
TPAoutputforce = force(point1:isize);
TPAoutputdisp = disp(point1:isize);
TPAoutputdata = [TPAoutputtime TPAoutputforce TPAoutputdisp];
STNoutputtime = time(point1:point3c)-time(point1);
STNoutputforce = force(point1:point3c)-force(point1);
STNoutputdisp = disp(point1:point3c)-disp(point1);
STNoutputstress = STNoutputforce/specimen_area;
STNoutputstrain = STNoutputdisp/specimen_height;% maybe mutiply 100 (%)
Fracture_stress = force(point2)/specimen_area;
Strength_of_material = force(point3c)/specimen_area;
E_range_start = round((point2-point1)/3);
E_range_end = round((point2-point1)/2);
[r,EModulus,b] = regression(STNoutputstrain(E_range_start:E_range_end)',STNoutputstress(E_range_start:E_range_end)');
figure
subplot(2,1,1),plot(TPAoutputtime,TPAoutputforce), xlabel('time'), ylabel('force'), grid on;
subplot(2,1,2),plot(TPAoutputtime,TPAoutputdisp), xlabel('time'), ylabel('disp'), grid on;
figure;
plot(STNoutputstrain, STNoutputstress), xlabel('strain'), ylabel('stress'), grid on;
figure
plotregression(STNoutputstrain(E_range_start:E_range_end)',STNoutputstress(E_range_start:E_range_end)');
end
  2 commentaires
Sriram Tadavarty
Sriram Tadavarty le 24 Mar 2020
Modifié(e) : Sriram Tadavarty le 24 Mar 2020
Can you provide the excel sheet? I suspect that there is nothing read for variable time_orig from excel sheet and thus causing that error.

Connectez-vous pour commenter.

Réponses (1)

Samatha Aleti
Samatha Aleti le 27 Mar 2020
This Error occurs when the data entered in the ranges is not numeric. In your code, data in the “timerange” is not numeric.
In this case, you can use the following syntax:
[num,txt,raw] = xlsread(___)
i.e., replace
time_orig = xlsread(filename, sheet, timerange);
with
[time_orig_num, time_orig_txt, raw] = xlsread(filename, sheet, timerange);
% Convert character cell array into numeric vector
time_orig = zeros(length(time_orig_txt),1);
for i = 1:length(time_orig_txt)
time_orig(i) = str2num(time_orig_txt{i});
end
You can refer the documentation page of “xlsread in following link:
Also, "xlsread" is not recommended.You can use "readtable" instead.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by