Blank figures using plot
8 views (last 30 days)
Show older comments
Ivaylo Ivanov
on 19 Jan 2020
Commented: Ivaylo Ivanov
on 20 Jan 2020
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
0 Comments
Accepted Answer
Image Analyst
on 19 Jan 2020
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);
Command window shows:
Starting loop #1 to compute 30001 values.
Starting loop #2 to compute 8001 values.
Starting loop #3 to compute 8001 values.
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!