From: Kelsea on
Hi,

I am trying to run this code:

function [ExtraOut] = SteadyStateStrainRateExtraOut(timedata,straindata),
%This function assumes data is in the format (zereod time, strain)
%and is coming from SeparateColumns or SeparatePKVYColumns. make sure
%fatigue strain is peak strains

% Length of the array.
a = length(timedata);

%Extracting columns from file.
Time = timedata;
Strain = straindata;

RT = input('Rupture time in hours ');
RTstart = RT*0.20;
RTend = RT*0.70;

indexStart = [];
indexEnd = [];

%Note: for fatigue tests (abs(T)-RTstart) must be <0.00015 (one less 0).
%Creep tests use 0.000015
for i = 1:a
if((i+1)<a)
if(abs(Time(i)-RTstart)<0.0000015)
indexStart = [indexStart;i];

elseif (abs(Time(i)-RTend)<0.0000015)
indexEnd = [indexEnd;i];
end
end
end

time20t070 = [];
strain20to70 = [];
StrainRate=[];
Rsquared=[];

Time_ones = [ones(a,1) Time];

for j = 1:size(indexStart)
time20t070 = [Time_ones(indexStart(j):indexEnd(j), 1:2)];
strain20to70 = [Strain(indexStart(j):indexEnd(j))];

[SSSR, Eint, R, Rint, Stats] = regress(strain20to70,time20t070);
StrainRate = [StrainRate; SSSR(2,1)];
Rsquared = [Rsquared; Stats(1,1)];
end

Time20TR = Time(indexStart);
Time70TR = Time(indexEnd);
Strn20TR = Strain(indexStart);
Strn70TR = Strain(indexEnd);
ExtraOut = [StrainRate Rsquared Time20TR Strn20TR Time70TR Strn70TR];
%{
for k = 1:size(indexStart)
timeStart = [timeStart;time(indexStart(k))];
strainStart = [strainStart;strain(indexStart(k))];
end

for j = 1:size(indexEnd)
timeEnd = [timeEnd;time(indexEnd(j))];
strainEnd = [strainEnd;strain(indexEnd(j))];
end

strainrate = ((strainEnd-strainStart)/(timeEnd-timeStart));
%}

end


So, the code calls for an input called "Time to rupture".

When I run it, sometimes it kicks out the error, below:
??? Attempted to access indexEnd(1); index out of bounds because
numel(indexEnd)=0.

Error in ==> SteadyStateStrainRateExtraOut at 41
time20t070 = [Time_ones(indexStart(j):indexEnd(j), 1:2)];

However, as I said before, it only does this sometimes. I've been playing with the part:
abs(T)-RTstart) must be <0.00015 to see if that may change it, but this doesn't seem to help very well.

Can anyone help me?
Thanks,

Kelsea
From: Andy on
The error message is clear. Look at this part of the code:

indexStart = [];
indexEnd = [];

%Note: for fatigue tests (abs(T)-RTstart) must be <0.00015 (one less 0).
%Creep tests use 0.000015
for i = 1:a
if((i+1)<a)
if(abs(Time(i)-RTstart)<0.0000015)
indexStart = [indexStart;i];

elseif (abs(Time(i)-RTend)<0.0000015)
indexEnd = [indexEnd;i];
end
end
end

indexEnd is initialized to [], and it only changes if, for some i, abs(Time(i)-RTend)<0.0000015. If that never happens, then indexEnd remains []. In the next for loop in your code,

time20t070 = [Time_ones(indexStart(j):indexEnd(j), 1:2)];

attempts to reference indexEnd(1) on the first iteration. If indexEnd is [], then there is no indexEnd(1), so you have an error.
From: Kelsea on
"Andy " <theorigamist(a)gmail.com> wrote in message <ht18m9$fon$1(a)fred.mathworks.com>...
> The error message is clear. Look at this part of the code:
>
> indexStart = [];
> indexEnd = [];
>
> %Note: for fatigue tests (abs(T)-RTstart) must be <0.00015 (one less 0).
> %Creep tests use 0.000015
> for i = 1:a
> if((i+1)<a)
> if(abs(Time(i)-RTstart)<0.0000015)
> indexStart = [indexStart;i];
>
> elseif (abs(Time(i)-RTend)<0.0000015)
> indexEnd = [indexEnd;i];
> end
> end
> end
>
> indexEnd is initialized to [], and it only changes if, for some i, abs(Time(i)-RTend)<0.0000015. If that never happens, then indexEnd remains []. In the next for loop in your code,
>
> time20t070 = [Time_ones(indexStart(j):indexEnd(j), 1:2)];
>
> attempts to reference indexEnd(1) on the first iteration. If indexEnd is [], then there is no indexEnd(1), so you have an error.


Thanks Andy for your help. I just started working with Matlab, so I tend to have many errors pop up.

For this part of the code:
indexStart = [];
indexEnd = [];

%Note: for fatigue tests (abs(T)-RTstart) must be <0.00015 (one less 0).
%Creep tests use 0.000015
for i = 1:a
if((i+1)<a)
if(abs(Time(i)-RTstart)<0.00015)
indexStart = [indexStart;i];

elseif (abs(Time(i)-RTend)<0.00015)
indexEnd = [indexEnd;i];
end
end
end

I changed if(abs(Time(i)-RTstart)<0.00015) and elseif (abs(Time(i)-RTend)<0.00015) from 0.0000015 to 0.00015.

Now I get a completely different error:
??? Error using ==> horzcat
CAT arguments dimensions are not consistent.

Error in ==> SteadyStateStrainRateExtraOut at 53
ExtraOut = [StrainRate Rsquared Time20TR Strn20TR Time70TR Strn70TR];

How can I remedy this? Thanks, and I look forward to your response.

Kelsea