How to plot the values found in a for loop?

1 view (last 30 days)
Nick Kavouris
Nick Kavouris on 24 Sep 2020
Commented: David Hill on 24 Sep 2020
I have the following code
for g=((-3*pi())/2):0.1:0
Ebca=X*(Ex*cos((pi()/6)+g)^2+Ey*sin((pi()/6)+g)^2+Gamxy*sin((pi()/6)+g)*cos((pi()/6)+g))
Ebcb=Ex*cos(-(pi()/6)+g)^2+Ey*sin(-(pi()/6)+g)^2+Gamxy*sin(-(pi()/6)+g)*cos(-(pi()/6)+g);
Ebcc=Ex*cos((pi()/2)+g)^2+Ey*sin((pi()/2)+g)^2+Gamxy*sin((pi()/2)+g)*cos((pi()/2)+g);
end
I need to plot each Ebca, Ebcb, Ebcc value found in the loop with respect to g, how would i do this?
I know i need to create an array with the values found for each function with each value of g but I do no know how to do this.

Answers (1)

David Hill
David Hill on 24 Sep 2020
Are X, Ex, Ey, Gamxy constants not listed? Recommned executing without loop; otherwise you need to index Ebca/Ebcb/Ebcc. Currently you are overriding them during each loop execution.
g=-3*pi/2:0.1:0
Ebca=X*(Ex*cos((pi/6)+g).^2+Ey*sin((pi/6)+g).^2+Gamxy*sin((pi/6)+g).*cos((pi/6)+g));
Ebcb=Ex*cos(-(pi/6)+g).^2+Ey*sin(-(pi/6)+g).^2+Gamxy*sin(-(pi/6)+g).*cos(-(pi/6)+g);
Ebcc=Ex*cos((pi/2)+g).^2+Ey*sin((pi/2)+g).^2+Gamxy*sin((pi/2)+g).*cos((pi/2)+g);
plot(g,Ebca,g,Ebcb,g,Ebcc);
  3 Comments
Nick Kavouris
Nick Kavouris on 24 Sep 2020
the code you provided me worked beautifully! thank you for the assistance
David Hill
David Hill on 24 Sep 2020
If you get a change, please accept the answer to close the question.

Sign in to comment.

Categories

Find more on Graphics Performance in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!