Finding and saving slopes of individual lines generated using for loop

I have an array T(4753*6), which are (x1,y1,x2,y2,x3,y3). I have plotted three profiles using for loop. Similarly, I want to calculate the slope of the plotted individual profiles and save it in the workspace using for loop. I am using the following code that is not working, Is there any other way to calculate the slope of individual profiles and save it?
hold on
for i=2:2:6
j=i-1
plot(T(:,j),T(:,i))
end
hold on
for i=2:2:6
j=i-1
p=polyfit(T(:,j),T(:,i),1)
end

 채택된 답변

KSSV
KSSV 2021년 3월 17일
hold on
for i=2:2:6
j=i-1
plot(T(:,j),T(:,i))
end
hold on
slope = zeros([],1) ;
count = 0 ;
for i=2:2:6
j=i-1
p=polyfit(T(:,j),T(:,i),1) ;
count = count+1 ;
slope(count) = p(1) ;
end

댓글 수: 2

Thanks a lot.
Further, I want to extract some part of the profile by indexing, to compute the slope of the required extracted profile. Is it possible to integrate my indexing code before calculating the slope of all the three cases as done above using for loop? It would also be acceptable if a separate array of the required indexed profile is created (x1,y1,x2,y2,x3,y3)-using for loop, which can be further defined separately and eventually used for slope computation.
indx=find(T(:,i)>0.1);
indx2=find(indx(:,1)>100);
q=indx2(1,1);
r=indx(q,1);
indx3=find(T(:,i)>100);
s=indx3(1,1);
Time=T(r:s,j);
In=T(r:s,i);
plot(Time,In) %This is the final x1,y1....x3,y3 that I need for all the cases

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

AD
2021년 3월 17일

댓글:

AD
2021년 3월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by