Correlation Code Not Outputting the intended values
이전 댓글 표시
Hi everyone,
I have an excel spreadsheet with three columns: cycle, force and strain. For each unique cycle value, the code calculates the correlation factor between incremental matrices of Force and Strain until the correlation drops below a threshold (I have it set to 0.99). The find_elasticlimit function outputs the largest strain value for each unique cycle count after which the correlation drops below the threshold.
The issue is this code is returning the maximum strain for some reason, what I would like instead is:
Only when the cycle count is an integer (the cycle column includes half cycles, i.e. 0.5,1.5,2.5 ...), start calculating the correlation factor between force and strain only when the strain is positive and increasing to the peak strain and return the elastic limit, that is the strain after which the correlation drops below the threshold. If the correlation never drops below the threshold, return the max strain for that cycle.
I'm attaching a sample data file for your convenience.
Thank you!
data=xlsread('Random.xlsx');
count=data(:,1);
strain=data(:,2);
force=data(:,3);
unique_counts=unique(count);
elasticlimit=zeros(size(unique_counts));
peakstrain=zeros(size(unique_counts));
valleystrain=zeros(size(unique_counts));
peakforce=zeros(size(unique_counts));
valleyforce=zeros(size(unique_counts));
for n=1:numel(unique_counts)
c=unique_counts(n);
rows=ismember(count,c);
strain_=strain(rows);
force_=force(rows);
%function call
elasticlimit(n)=find_elasticlimit(force_,strain_);
%Retrieve the peak strain/force from each cycle
peakstrain(n)=max(strain_);
[peakstrain(n), idx]=max(strain_);
peakforce(n)=force_(idx);
%Retrieve the valley strain/force from each cycle
valleystrain(n)=min(strain_);
[valleystrain(n), idy]=min(strain_);
valleyforce(n)=force_(idy);
end
rankedelastic=rank_elastic(elasticlimit);
function elasticlimit=find_elasticlimit(force,strain,thres)
if nargin<3,thres=0.99;end%set default
found=false;
for N=2:numel(strain)
R=corrcoef(strain(1:N),force(1:N));
R=R(2);
if R<thres,found=true;break,end
end
if found
elasticlimit=strain(N-1);
else
%return an error condition or error
elasticlimit=max(strain_);
end
end
댓글 수: 1
Sargondjani
2021년 6월 23일
It would be very helpful if you shorten the question and code. Be precise which part of your code does not do what you want.
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Correlation and Convolution에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!