Issue with fprintf in a loop
显示 更早的评论
Here is my code :
close all; clear all; clc
g = 1.4; % Specific heat ratio for air
beta = 0:pi/1800:pi/2; % Range for shock wave angle in rad
m = 0;
% theta
for M1 = 1:0.5:10 % Upstream Mach Number from 1 to 10
m = m+1;
p(m)=fprintf('%.2n' , M1);
% theta-beta-M relation
A = ((M1^2)*((sin(beta)).^2))-1;
B = ((g+(cos(2*beta)))*M1^2)+2;
theta = atan(2*cot(beta).*A./B);
% max. theta for a M1
maxtheta(m) = max(theta); % max theta for the Mach No.
maxbeta(m) = beta(theta==maxtheta(m)); % find the beta for max. theta
plot(theta*180/pi,beta*180/pi,'-b')
if M1<=5
x(m)=(theta(beta==60*pi/180)*180/pi);
if x(m)>0
txt= sprintf('M1=%d',p(m));
text(x(m),60,txt)
end
end
hold on
end
plot(maxtheta*180/pi,maxbeta*180/pi,'-r','Linewidth',1.5)
xlabel('\theta')
ylabel('\beta')
axis([0 50 0 90])
When i don't use the fprintf function, the M1 displayed on the graph have many zeros. SO i am trying to get rid of those useless zeros with fprintf. However when I use Fprintf in my loop it only returns 4 and not 1.0 ; 1.5 ; 2.0 and so on.
Could someone help me on that ?
Thank you
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

