While loop to detect 0 slope
Show older comments
Hello everyone,
so I'm currently trying to make a code that will separate some data. To do so, I came up with a code that I thought would work, and I've tried looking at the what the error message mean, but I cant understand. My code is the follwoing
*g=0; j=0; A=[5 5]; h=0; slope=5; while (g<1785) & (A(1,1)>0) & (h<0.15) h = AverageStrain(1+g:20+g,:); i = AverageStress(1+g:20+g,:); A = polyfit(h,i,1); j = g+10; g = g+20; end
Cycle1UpStrain=AverageStrain(0:j,1);*
The error message i receive is ;
*Subscript indices must either be real positive integers or logicals.
Error in MTSAnalyser (line 43) Cycle1UpStrain=AverageStrain(0:j,1);*
here, the files AverageStress and AverageStraain are 1785x1 variables. I tried doing a linear fit of 20 data points at the time so that when the linear slope calculated is 0 are negative, it stops and extracts the number j.
j would be used to create a variable made of a fraction of AverageStress and AverageStrain, data points 1 to j. (afterwards I would make it something like j to a new variable limit)
Also, my value of A always ends in something like [574, -64], which is weird since I wanted it to stop at a slope equal 0 or smaller, which is the first row, first column of A.
I'm quite new to Matlab, so try not to assume I know a whole bunch.
Thank you for your help! N
1 Comment
Star Strider
on 4 Jun 2014
Formatted code:
g=0;
j=0;
A=[5 5];
h=0;
slope=5;
while (g<1785) & (A(1,1)>0) & (h<0.15)
h = AverageStrain(1+g:20+g,:);
i = AverageStress(1+g:20+g,:);
A = polyfit(h,i,1);
j = g+10;
g = g+20;
end
Accepted Answer
More Answers (0)
Categories
Find more on Logical in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!