I am trying to insert a number for each curve in my plot, the M matrix is 1 x 100, and doing for each is tedious and non efficient method.
here is part of my code where M is limited to 1x3 matrix:
B=0:.001:pi/2;
Y=1;
M=[1 2 3];
for j=1:1:length(M)
D=zeros;
for i=1:1:length(B)
D(i)=atan(( 2*cot(B(i))*(M(j)^2*sin(B(i))^2-1) )/( 2+M(j)^2*(Y+cos(2*B(i))) ));
end
figure(1)
hold on
plot(rad2deg(D),rad2deg(B))
end
B_max=zeros(1,length(M));
D_max=zeros(1,length(M));
for k=1:1:length(M)
S='M(k)';
B_max(k)=asin(sqrt(((Y+1)/(4*Y))-(1/(Y*M(k)^2))*(1-sqrt((Y+1)*((1+((Y-1)*M(k)^2/2))+((Y+1)*M(k)^4/16))))));
D_max(k)=atan((2*cot(B_max(k))*(M(k)^2*sin(B_max(k))^2-1))/(2+M(k)^2*(Y+cos(2*B_max(k))) ));
text(rad2deg(D_max(k)),rad2deg(B_max(k)),S(1))
end

 採用された回答

Star Strider
Star Strider 2017 年 11 月 26 日

0 投票

Change the text call to:
text(rad2deg(D_max(k)),rad2deg(B_max(k)), sprintf('M(%d)',M(k)))
That should do what you want.

2 件のコメント

Saad Moalwi
Saad Moalwi 2017 年 11 月 26 日
Small issue, I would like to see the number as written (3.5) not (3.500000e+00)
Star Strider
Star Strider 2017 年 11 月 26 日
I used the ‘%d’ format descriptor, because ‘k’ is an integer. If you want the format you describe, use ‘%.1f’ instead:
text(rad2deg(D_max(k)),rad2deg(B_max(k)), sprintf('M(%.1f)',M(k)))
That will work.

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

その他の回答 (0 件)

カテゴリ

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by