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!