Hello,
I'm having trouble fixing the annotations on my graph. For the annotations at the throat and exit, the value isn't that clear. Is there any reason why it's like this, and if I can change it so it's more clear? I've attached the code and a picture of my plot.
Thanks in advance
plot(i,r1(l), '.b'); hold on
plot(i,r2(l),'.b'); hold on
yline(0,'-.k');
xline(0,'-.r');
xline(-L/2,'-.r');
xline(L,'-.r');
title ('Plot of Nozzle Shape');
xlabel('Axial distance from the throat (mm)');
ylabel('Radius (mm)');
txt1 = ['Throat, d=' num2str(2*min(r1)) 'mm'];
text(0,1,txt1);
txt2 = ['Inlet, d=' num2str(2*r1(1)) 'mm'];
text(-L/2,1,txt2);
txt3 = ['Exit, d=' num2str(2*r1(end)) 'mm'];
text(0.85*L,1,txt3)

 採用された回答

Mario Malic
Mario Malic 2020 年 11 月 15 日

0 投票

Is your piece of code in for loop?
Guessing that r1(1) and r1(end) are changing and there are many different texts on top of each other.

4 件のコメント

Nadine Nassar
Nadine Nassar 2020 年 11 月 15 日
Yes it is. But I thought using those commands will output the values when the for loop is finished. So what you're saying is that after every loop, it outputs r1(1) and r1(end)?
(Here's the loop btw)
l=0; %Defining the array
for i=(-L/2):2:L %Dividing the nozzle length into increments of 1, throat located at the centre
l=l+1; %Adds new value to array
r(l) =(r_throat^2)*(1 + (2.5*((i/L)^2))); %squared value of r from the equation of the nozzle
r1(l) = sqrt(r(l)); %Positive value of r
r2(l) = -sqrt(r(l)); %Negative value of r
end
Mario Malic
Mario Malic 2020 年 11 月 15 日
編集済み: Mario Malic 2020 年 11 月 15 日
For the sake of people who are reading your code in future, please don't use lowercase character 'L' as your index, I thought it was number '1'.
Put this outside of for loop and it should work.
txt1 = ['Throat, d=' num2str(2*min(r1)) 'mm'];
text(0,1,txt1);
txt2 = ['Inlet, d=' num2str(2*r1(1)) 'mm'];
text(-L/2,1,txt2);
txt3 = ['Exit, d=' num2str(2*r1(end)) 'mm'];
text(0.85*L,1,txt3)
However, you should avoid using for loop here, and simplify your code. I think this would get you the same r you have at the end of your loop.
i=(-L/2):2:L
r=(r_throat^2)*(1 + (2.5*((i/L).^2)));
Nadine Nassar
Nadine Nassar 2020 年 11 月 15 日
Okay, i'll change it. I also tried your suggestion of not using a for loop and I got the same results, and realised the computational time was much faster this time. The text on the plot is also fixed now.
Thanks a lot for yor help
Mario Malic
Mario Malic 2020 年 11 月 15 日
Cool! You're welcome.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by