how to plot 5 graph together and 1 graph separately?
Show older comments
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
ali hassan
on 29 Jan 2022
please share your code.
ali hassan
on 29 Jan 2022
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')
disp([c,d]);
%b)ii)
[e,f]=min(sdelta);
[g,h]=min(e);
disp('min value and number of days')
disp([g,h]);
%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 ')
disp(numberofdays);
%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');
disp([dni',sdeltai'])
%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
ali hassan
on 29 Jan 2022
i think it works fine now?
prem kumar
on 29 Jan 2022
Cris LaPierre
on 29 Jan 2022
Yes it did. Look above.
prem kumar
on 29 Jan 2022
prem kumar
on 29 Jan 2022
prem kumar
on 29 Jan 2022
Edited: Cris LaPierre
on 29 Jan 2022
Cris LaPierre
on 29 Jan 2022
Edited: Cris LaPierre
on 29 Jan 2022
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.
prem kumar
on 29 Jan 2022
prem kumar
on 29 Jan 2022
Voss
on 29 Jan 2022
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.
prem kumar
on 29 Jan 2022
Voss
on 29 Jan 2022
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.
Accepted Answer
More Answers (0)
Categories
Find more on Line Plots 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!




