how to plot 5 graph together and 1 graph separately?

hello friends i would like to ask how to plot 5 graph together and 1 graph separately...when i run my code for plotting it gives figure which includes all my plots.the 1 graph separately that i wanted to plot is in my Part A a) whereelse the other 5 graph are from Part B a).I tried to use section break and naming the figure separately but it didnt work...any hints ?

16 Comments

please share your code.
its kinda big but hope i dunt violate the rules for posting the code
%Part A
% a)plot graph solar declination versus the day number
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
figure(1)
plot(dn,sdelta);
grid on
% b)i)
[a,b]=max(sdelta);
[c,d]=max(a);
disp('max value and number of days')
max value and number of days
disp([c,d]);
23.4498 1.0000
%b)ii)
[e,f]=min(sdelta);
[g,h]=min(e);
disp('min value and number of days')
min value and number of days
disp([g,h]);
-23.4498 1.0000
%b)iii)
sdelta = rand(1,365);
targetangle = [-0.3 0.3];
Numberdays = sdelta >= targetangle(1) ...
& sdelta <= targetangle(2);
numberofdays = nnz(Numberdays);
disp('the number days for equinox ')
the number days for equinox
disp(numberofdays);
111
%c)
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
dni = [15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] ;
sdeltai = interp1(dn,sdelta,dni);
disp(' dni sdeltai');
dni sdeltai
disp([dni',sdeltai'])
15.0000 -21.2695 45.0000 -13.6198 75.0000 -2.4177 105.0000 9.4149 135.0000 18.7919 165.0000 23.2676 195.0000 21.6746 225.0000 14.4284 255.0000 3.4190 285.0000 -8.4822 315.0000 -18.1710 345.0000 -23.1205
%PartB a)
for dn=100
for L=0
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta1=asind(PP);
end
for L=20
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta2=asind(PP);
end
for L=40
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP1=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta3=asind(PP1);
end
for L=60
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP2=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta4=asind(PP2);
end
for L=80
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP3=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta5=asind(PP3);
end
hold on
figure(2)
grid on
plot(k,Beta1)
plot(k,Beta2)
plot(k,Beta3)
plot(k,Beta4)
plot(k,Beta5)
end
do you want the 05 plots in part B(a) on a single plot?
%Part A
% a)plot graph solar declination versus the day number
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
figure(1)
plot(dn,sdelta);
grid on
% b)i)
[a,b]=max(sdelta);
[c,d]=max(a);
disp('max value and number of days')
max value and number of days
disp([c,d]);
23.4498 1.0000
%b)ii)
[e,f]=min(sdelta);
[g,h]=min(e);
disp('min value and number of days')
min value and number of days
disp([g,h]);
-23.4498 1.0000
%b)iii)
sdelta = rand(1,365);
targetangle = [-0.3 0.3];
Numberdays = sdelta >= targetangle(1) ...
& sdelta <= targetangle(2);
numberofdays = nnz(Numberdays);
disp('the number days for equinox ')
the number days for equinox
disp(numberofdays);
117
%c)
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
dni = [15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] ;
sdeltai = interp1(dn,sdelta,dni);
disp(' dni sdeltai');
dni sdeltai
disp([dni',sdeltai'])
15.0000 -21.2695 45.0000 -13.6198 75.0000 -2.4177 105.0000 9.4149 135.0000 18.7919 165.0000 23.2676 195.0000 21.6746 225.0000 14.4284 255.0000 3.4190 285.0000 -8.4822 315.0000 -18.1710 345.0000 -23.1205
%PartB a)
for dn=100
for L=0
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta1=asind(PP);
end
for L=20
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta2=asind(PP);
end
for L=40
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP1=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta3=asind(PP1);
end
for L=60
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP2=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta4=asind(PP2);
end
for L=80
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP3=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta5=asind(PP3);
end
figure(2)
grid on
plot(k,Beta1)
hold on;
plot(k,Beta2)
plot(k,Beta3)
plot(k,Beta4)
plot(k,Beta5)
hold off;
end
i think it works fine now?
yes the 5 graph got separated but my first plot in Part A a) didnt give output
why does mine didnt give me this output though i didnt change anything there....let me copy the whole code first sorry to cause trouble
yup i copied the whole code but it only gives me output of the 5 plot graph unfortunately..
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
figure(1)
plot(dn,sdelta);
grid on
title('solar declination vs number of days')
xlabel('number of days')
ylabel('solar declination')
% b)i)
[a,b]=max(sdelta);
[c,d]=max(a);
disp('max value and number of days')
max value and number of days
disp([c,d]);
23.4498 1.0000
%b)ii)
[e,f]=min(sdelta);
[g,h]=min(e);
disp('min value and number of days')
min value and number of days
disp([g,h]);
-23.4498 1.0000
%b)iii)
sdelta = rand(1,365);
targetangle = [-0.3 0.3];
Numberdays = sdelta >= targetangle(1) ...
& sdelta <= targetangle(2);
numberofdays = nnz(Numberdays);
disp('the number days for equinox ')
the number days for equinox
disp(numberofdays);
119
%c)
dn=1:1:365;
x=(360/365*(dn+284));
sdelta=23.45*(sind(x));
dni = [15, 45, 75, 105, 135, 165, 195, 225, 255, 285, 315, 345] ;
sdeltai = interp1(dn,sdelta,dni);
disp(' dni sdeltai');
dni sdeltai
disp([dni',sdeltai'])
15.0000 -21.2695 45.0000 -13.6198 75.0000 -2.4177 105.0000 9.4149 135.0000 18.7919 165.0000 23.2676 195.0000 21.6746 225.0000 14.4284 255.0000 3.4190 285.0000 -8.4822 315.0000 -18.1710 345.0000 -23.1205
%PartB a)
for dn=100
for L=0
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta1=asind(PP);
end
for L=20
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta2=asind(PP);
end
for L=40
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP1=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta3=asind(PP1);
end
for L=60
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP2=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta4=asind(PP2);
end
for L=80
sdelta=7.53377356668594;
k=0.5:0.5:24;
lamda=15*(12-k);
PP3=sind(sdelta).*sind(L)+cosd(sdelta).*cosd(L).*cosd(lamda);
Beta5=asind(PP3);
end
figure(2)
grid on
plot(k,Beta1)
hold on;
plot(k,Beta2)
plot(k,Beta3)
plot(k,Beta4)
plot(k,Beta5)
hold off;
end
%b)
disp('dn=100')
dn=100
disp(' Latitude degree,L' )
Latitude degree,L
disp('============================================================')
============================================================
disp('Solar time,k 0 20 40 60 80 ')
Solar time,k 0 20 40 60 80
disp('============================================================')
============================================================
disp([k',Beta1',Beta2',Beta3',Beta4',Beta5'])
0.5000 -79.3848 -61.4942 -41.9636 -22.2035 -2.3818 1.0000 -73.2533 -58.7593 -40.4872 -21.4229 -2.1299 1.5000 -66.3345 -54.6691 -38.1227 -20.1456 -1.7149 2.0000 -59.1541 -49.6347 -34.9884 -18.4049 -1.1441 2.5000 -51.8601 -43.9659 -31.2130 -16.2427 -0.4272 3.0000 -44.5075 -37.8709 -26.9185 -13.7070 0.4235 3.5000 -37.1214 -31.4845 -22.2121 -10.8482 1.3936 4.0000 -29.7149 -24.8945 -17.1839 -7.7180 2.4670 4.5000 -22.2953 -18.1592 -11.9083 -4.3670 3.6258 5.0000 -14.8675 -11.3188 -6.4467 -0.8450 4.8509 5.5000 -7.4349 -4.4020 -0.8508 2.7997 6.1222 6.0000 0 2.5701 4.8344 6.5197 7.4187 6.5000 7.4349 9.5808 10.5680 10.2675 8.7190 7.0000 14.8675 16.6158 16.3098 13.9950 10.0015 7.5000 22.2953 23.6622 22.0180 17.6520 11.2446 8.0000 29.7149 30.7060 27.6450 21.1854 12.4269 8.5000 37.1214 37.7309 33.1333 24.5381 13.5278 9.0000 44.5075 44.7141 38.4093 27.6485 14.5276 9.5000 51.8601 51.6205 43.3753 30.4508 15.4082 10.0000 59.1541 58.3878 47.8989 32.8758 16.1531 10.5000 66.3345 64.8922 51.8040 34.8547 16.7481 11.0000 73.2533 70.8531 54.8683 36.3232 17.1816 11.5000 79.3848 75.5702 56.8468 37.2280 17.4453 12.0000 82.4662 77.5338 57.5338 37.5338 17.5338 12.5000 79.3848 75.5702 56.8468 37.2280 17.4453 13.0000 73.2533 70.8531 54.8683 36.3232 17.1816 13.5000 66.3345 64.8922 51.8040 34.8547 16.7481 14.0000 59.1541 58.3878 47.8989 32.8758 16.1531 14.5000 51.8601 51.6205 43.3753 30.4508 15.4082 15.0000 44.5075 44.7141 38.4093 27.6485 14.5276 15.5000 37.1214 37.7309 33.1333 24.5381 13.5278 16.0000 29.7149 30.7060 27.6450 21.1854 12.4269 16.5000 22.2953 23.6622 22.0180 17.6520 11.2446 17.0000 14.8675 16.6158 16.3098 13.9950 10.0015 17.5000 7.4349 9.5808 10.5680 10.2675 8.7190 18.0000 0 2.5701 4.8344 6.5197 7.4187 18.5000 -7.4349 -4.4020 -0.8508 2.7997 6.1222 19.0000 -14.8675 -11.3188 -6.4467 -0.8450 4.8509 19.5000 -22.2953 -18.1592 -11.9083 -4.3670 3.6258 20.0000 -29.7149 -24.8945 -17.1839 -7.7180 2.4670 20.5000 -37.1214 -31.4845 -22.2121 -10.8482 1.3936 21.0000 -44.5075 -37.8709 -26.9185 -13.7070 0.4235 21.5000 -51.8601 -43.9659 -31.2130 -16.2427 -0.4272 22.0000 -59.1541 -49.6347 -34.9884 -18.4049 -1.1441 22.5000 -66.3345 -54.6691 -38.1227 -20.1456 -1.7149 23.0000 -73.2533 -58.7593 -40.4872 -21.4229 -2.1299 23.5000 -79.3848 -61.4942 -41.9636 -22.2035 -2.3818 24.0000 -82.4662 -62.4662 -42.4662 -22.4662 -2.4662
%c)
for L=0
max(Beta1);
disp('max value at L=80')
disp(max(Beta1));
end
max value at L=80
82.4662
for L=20
max(Beta2);
disp('max value at L=20')
disp(max(Beta2));
end
max value at L=20
77.5338
for L=40
max(Beta3);
disp('max value at L=40')
disp(max(Beta3));
end
max value at L=40
57.5338
for L=60
max(Beta4);
disp('max value at L=60')
disp(max(Beta4));
end
max value at L=60
37.5338
for L=80
max(Beta5);
disp('max value at L=80')
disp(max(Beta5));
end
max value at L=80
17.5338
this is the latest code but the top one is all the same with me and yours but it didnt gave me the same output
by any chance is it my matlab program have error or the setting is different from yours?
I'm afraid I don't understand. It is the same or it is different? No, there is no setting that I can think of that would cause the code to run differently for you.
If you have additional code that you are not sharing, it is possible your variables have different values when you plot. Try clearing your workspace (clear) and closing all figures (close all), then run just the code above.
no friend i use the same matlab version r2021b but when i run the code here it gives me the output that i want but when i run in my software it only show me output one of the graph...no all the variables are exatcly same...I will try to do the clear and close all and try to rerun it back.
yes after i close my software and rerun it its fine now thank Mr.Chris and Mr.Ali Hassan for helping me out
It's possible that figure 1 is not visible or is off the screen somewhere. Try putting "close all" at the beginning of your code to close existing figures so that you are sure to be plotting into new figures when the code runs.
Alternatively, you could put break points around the part of the code where figure 1 is plotted in and see what you can see as the code runs. You might want to also use findobj() or findall() to retrieve the handles to existing figures to inspect or delete them.
thanks Mr.Benjamin i managed to get it after i use close all and close my software and re-run it.
That's good news. A tip: if you want to plot into a new figure, use "figure()" with no arguments because "figure(2)" will plot into the existing figure 2 if it exists.

Sign in to comment.

 Accepted Answer

Cris LaPierre
Cris LaPierre on 29 Jan 2022
Edited: Cris LaPierre on 30 Jan 2022
Copying the solution given above to an answer.
Try clearing your workspace (clear) and closing all figures (close all), then run just the code above.

More Answers (0)

Categories

Products

Release

R2021b

Tags

Community Treasure Hunt

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

Start Hunting!