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

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 个评论

Thanks for reaching out Catalytic. The for-loop is under: function plotcirc(obj)

回答(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 个评论

Thanks for your input Catalytic. I am a Matlab novice. Where exactly should this be implemented in the original code? Also, what (and where) would the output file be? Thanks again.
I have attached a screenshot of an Excel file that I created, which contains the data I manually extracted from running the aforementioned code. We would really like to have Matlab generate it automatically. If anyone can help with this, we would realy appreciate it. Thanks in advance for any help you could offer.
screenshot-arcinfo.JPG
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)
Catalytic,
The short answer is, Matlab is required for this part of our research.
To address your comment a bit further...
As in any situation when learning something new, one must acquire a "critical mass" of information before becoming self-sustaining. In other words, I won't be a novice forever.
Furthermore, I mentioned to you that I am a Matlab novice so that you would know that I am not at your level of knowledge with Matlab, and so that you would be able to adjust your tutoring approach accordingly.
Back when I was a math/physics tutor (college staff) about 20-25 years ago, the first thing I would always try to find out about my students was the level of knowledge they had on the topic they needed tutoring in. I did this because it set the stage for how I would approach presenting new information to them. For example, I would never drop a differential equation on someone who was having trouble in their algebra-based physics course.
I believe this is the key to effective tutoring, but I find that most tutors don't even realize the importance of this step. Professors teach at their own level--regardless of who is ready to grasp what they are teaching. Tutors, however, need to have more empathy than that, and they must be able to come down to the level of the student. Otherwise, they will be of no help to the student. In any event, thanks for all the help you have provided thus far.
Best,
Steve
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.
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!
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.

此问题已关闭。

产品

版本

R2019a

提问:

2019-11-20

关闭:

2021-8-20

Community Treasure Hunt

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

Start Hunting!

Translated by