Could someone write some code to extract details within a for loop?
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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:
- arc lengths
- arc radii
- starting/ending points of arcs (triplet center points)
- 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!
Answers (1)
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
Steve
on 21 Nov 2019
Steve
on 21 Nov 2019
Catalytic
on 21 Nov 2019
Steve, if you are a Matlab novice to that degree, I have to wonder why you are using Matlab to meet your needs. You clearly do not know enough to take control/ownership of the code that is given you, and will be reliant on constant support from the forum for every bit of tweaking and trouble-shooting.
To answer your question, though, the function I have posted can be placed anywhere that is visible to the code you plan to call it from. It could be placed in its own mfile, for example, in a folder that is on the Matlab path. It would be very natural, though, to include it in the classdef file you have posted for us as an additional method of that class.
As for the output, the function does not write the output to a file. As most functions do, it returns the output in a structure variable. For example, when invoked as follows, it will return the output in a variable named "stuff".
stuff=getStuff(tgraph,arcNumber)
Steve
on 21 Nov 2019
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
on 22 Nov 2019
Steve
on 23 Nov 2019
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!