MATLAB Answers

Could someone write some code to extract details within a for loop?

3 views (last 30 days)
Steve
Steve on 20 Nov 2019
Commented: Steve on 23 Nov 2019
In my previous post, I was given some code that works great, but I need to extract some details that are mentioned within one of the for-loops, namely:
  1. arc lengths
  2. arc radii
  3. starting/ending points of arcs (triplet center points)
  4. thetas (w/ corresponding theta1, theta2 angles) for each arc.
Can anyone help me to extract and store these details (along with index/node numbers) within a single variable/file?
Thanks in advance for your help!

  2 Comments

Steve
Steve on 20 Nov 2019
Thanks for reaching out Catalytic. The for-loop is under: function plotcirc(obj)

Sign in to comment.

Answers (1)

Catalytic
Catalytic on 21 Nov 2019
Edited: Catalytic on 21 Nov 2019
Something like this....
function stuff=getStuff(tgraph,arcNumber)
AP=tgraph.ArcPoints;
i=arcNumber;
C1=AP(:,1,i); C2=AP(:,4,i);
V1=AP(:,2,i); V2=AP(:,3,i);
L=norm(C2-C1);
U=(C2-C1)/L;
dV1=(V1-C1)/norm(V1-C1);
dV2=(V2-C2)/norm(V2-C2);
stuff.theta1=acosd(dot( dV1, U) );
stuff.theta2=acosd(dot( dV2, -U) );
stuff.theta=(theta1+theta2)/2;
stuff.arcradius=norm(C1-C2)/(2*sind(theta));
stuff.C1=C1;
stuff.C2=C2;
stuff.nodeNumber=findedge(tgraph.Cgraph,i);
end

  7 Comments

Show 4 older comments
Steven Lord
Steven Lord on 22 Nov 2019
Since you are a MATLAB novice, have you considered working through the MATLAB Onramp tutorial? This free two hour tutorial that combines video tutorials with hands-on exercises is designed to help new users quickly learn the fundamentals of how to work with MATLAB. To access it, click on the Support link at the top of this page then click on Tutorials in the Getting Started section of the Support page.
Steve
Steve on 22 Nov 2019
Thank you Steven. I didn't even know about the MATLAB Onramp tutorial, but I will definitely check it out now that I know about it. Thanks again!
Steve
Steve on 23 Nov 2019
By the way Catalytic, thank you for your input. However, I could not get your code/function (shown above) to run, as it was generating errors.

Sign in to comment.

Sign in to answer this question.

Products


Release

R2019a