How to make a linear regression from an excel file

22 ビュー (過去 30 日間)
Nick Elias
Nick Elias 2021 年 3 月 15 日
編集済み: Rik 2021 年 3 月 23 日
Hi all,
This question is related to mechanics of materials if anyone can help. I have an excel file (a large one, 102k rows) with three columns: cycle count, force and strain.
Data was taken at a frequency of 8Hz (8 datapoints/sec, each cycle count lasts for about 40 rows) and I need to write a code to find the two points in each cycle (one in the increasing portion of the cycle, the other in the decreasing portion) where the correlation between strain and force becomes no longer linear (i.e. R^2 less than 95%), that is the elastic limit of the material. Basically the output would be a matrix with a number of rows equal to the number of cycles and three columns: cycle count, max elastic limit, min elastic limit.
Thank you for anything!
  4 件のコメント
Rik
Rik 2021 年 3 月 15 日
OK, so which part of the coding is causing you trouble? From what I understand you want to do an analysis on the parts of your data separatly for every value of cycle. How did you try to separate the several chunks?
Nick Elias
Nick Elias 2021 年 3 月 15 日
I have no clue about how to go about that in Matlab, basically the array size will not be the same for every cycle as I have to keep track of the absolute value of strain and calculate the correlation for a set of datapoints until the strain trend changes direction.

サインインしてコメントする。

回答 (1 件)

Rik
Rik 2021 年 3 月 15 日
編集済み: Rik 2021 年 3 月 18 日
You can use the unique function and a loop.
(edited to include a custom function to extract a specific strain value)
data=xlsread('Sample Data.xlsx');
count=data(:,1);
strain=data(:,2);
force=data(:,3);
unique_counts=unique(count);
elasticlimit=zeros(size(unique_counts));
meanstrain=zeros(size(unique_counts));
for n=1:numel(unique_counts)
c=unique_counts(n);
rows=ismember(count,c);
strain_=strain(rows);
force_=force(rows);
%now you have the strain and the force for a specific cycle
%here you can do the processing you need
elasticlimit(n)=find_elasticlimit(force_,strain_);
%you can also use simple functions here, like mean():
meanstrain(n)=mean(strain_);
end
disp(elasticlimit.')
0.0109 -0.0084 0.0060 -0.0093 0.0070 -0.0098 NaN
function elasticlimit=find_elasticlimit(force,strain,thres)
%Write an explanation for what this function does here.
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
%you should decide what is appropriate
elasticlimit=NaN;
end
end
  27 件のコメント
Nick Elias
Nick Elias 2021 年 3 月 23 日
I tried going over Onramp but there wasn't something covering the second output of max/min. No Matlab users around me either so I'm stuck. I used the search function but couldn't come across a similar situation.
Rik
Rik 2021 年 3 月 23 日
編集済み: Rik 2021 年 3 月 23 日
Unaccepting my answer comes across as a bit childish.
You need to use the second output of min. That second output contains indices. You can use those indices on the original vector you use in min, or for another vector.
v1=[9 0 6];
v2=[2 4 6];
[val,ind]=min(v1)
val = 0
ind = 2
v2(ind)
ans = 4

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by