Blank figures using plot

조회 수: 4 (최근 30일)
Ivaylo Ivanov
Ivaylo Ivanov 2020년 1월 19일
댓글: Ivaylo Ivanov 2020년 1월 20일
I am running the following code and when the figures pop-up, they are blank without any lines.
I have tried running the Matlab in the software mode, thinking that the problem is in the OpenGL, but nothing changed.
So the error must be in the code , but I cannot figure out where. I appreacate any help on this, as I am stuck..
c1=3.74*10^8;
c2=1.44*10^4;
T1=30;
T2=90;
T3=120;
a1=0;
a2=0;
a3=0;
max1=0;
max2=0;
max3=0;
figure(1);
for a=0:0.01:300
M=c1/((a^5)*(exp(c2/(a*T1))-1));
plot(a,M,'b')
if M>max3
max3=M; a3=a;
end
hold on
end
figure(2);
for a=0:0.01:80
M=c1/((a^5)*(exp(c2/(a*T2))-1));
plot(a,M,'r')
if M>max2
max2=M; a2=a;
end
hold on
end
figure(3);
for a=0:0.01:80
M=c1/((a^5)*(exp(c2/(a*T3))-1));
plot(a,M,'g')
if M>max1
max1=M; a1=a;
end
hold on
end

채택된 답변

Image Analyst
Image Analyst 2020년 1월 19일
Try this:
clc
clear all
close all
c1 = 3.74*10^8;
c2 = 1.44*10^4;
T1 = 30;
T2 = 90;
T3 = 120;
a1 = 0;
a2 = 0;
a3 = 0;
max1 = 0;
max2 = 0;
max3 = 0;
subplot(1, 3, 1);
a = 0:0.01:300;
M = zeros(1, length(a));
fprintf('Starting loop #1 to compute %d values.\n', length(a));
for k = 1 : length(a)
M(k) = c1/((a(k)^5)*(exp(c2/(a(k)*T1))-1));
if M(k)>max3
max3 = M(k);
a3 = a;
end
hold on
end
plot(a, M, 'b-', 'LineWidth', 2)
grid on;
xlabel('a', 'FontSize', 15);
ylabel('M', 'FontSize', 15);
drawnow;
subplot(1, 3, 2);
a = 0:0.01:80;
M = zeros(1, length(a));
fprintf('Starting loop #2 to compute %d values.\n', length(a));
for k = 1 : length(a)
M(k) = c1/((a(k)^5)*(exp(c2/(a(k)*T2))-1));
if M(k) > max2
max2 = M(k);
a2 = a;
end
hold on
end
plot(a, M, 'r-', 'LineWidth', 2)
grid on;
xlabel('a', 'FontSize', 15);
ylabel('M', 'FontSize', 15);
drawnow;
subplot(1, 3, 3);
a = 0:0.01:80;
M = zeros(1, length(a));
fprintf('Starting loop #3 to compute %d values.\n', length(a));
for k = 1 : length(a)
M(k) = c1/((a(k)^5)*(exp(c2/(a(k)*T3))-1));
if M(k) > max1
max1 = M(k);
a1 = a;
end
hold on
end
darkGreen = [0, 0.5, 0];
plot(a, M, 'g', 'Color', darkGreen, 'LineWidth', 2)
grid on;
xlabel('a', 'FontSize', 15);
ylabel('M', 'FontSize', 15);
0000 Screenshot.png
Command window shows:
Starting loop #1 to compute 30001 values.
Starting loop #2 to compute 8001 values.
Starting loop #3 to compute 8001 values.
  댓글 수: 1
Ivaylo Ivanov
Ivaylo Ivanov 2020년 1월 20일
Thank you for the code and your work. I would never though on it from this side.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by