How to add different size arrays to existing graph
1 次查看(过去 30 天)
显示 更早的评论
I cant get the AM_O, AM_15D, and AM_15G in part 3 of my code to plot onto the existing SolarIrradiance.fig that i made earlier, this is the code that i have so far, the am's are 2002x1 and lambda is a 1x300
close
clear
clc
[Inserted break so folks can copy/paste w/o wiping out their existing environment...dpb]
r_d = 1.50e11; % distance from Earth to Sun
r_s = (1.39e9)/2; % radius of the sun
fw =(r_s/r_d)^2;
t_s = 5800; % temp in kelvin
h = 6.626e-34; % in J*s
k_b = 1.381e-23; % in J/K
c = 2.998e8; % in m/s
syms lambda L_sun
lambda = (0.001:0.01:3)*1e-6;
L_sun = fw .* (2*pi*h*c.^2) ./ lambda.^5 .*...
1./(exp((h*c)./(lambda*k_b*t_s)) -1);
figure(1)
plot(lambda, L_sun, 'b-', 'LineWidth', 2);
xlim([0 3e-6]);
xlabel('Wavelength (um)');
ylabel('Spectral Irradiance (W*m^2/m^-1)');
legend('L_s_u_n')
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperPosition', [0 0 6.75 5]);
print('SolarIrradiance.tif', '-dpng', '-r600')
saveas(gcf, 'SolarIrradiance.fig')
%%
% Part 2.
maxL_sun = max(L_sun);
lambda_max = lambda(51);
% i. this falls in the visible region
% ii. uv = 6.4%, vis = 48%, and ir = 45.6%
% the energy for uv = 87, vis = 565, and ir = 623
UV = L_sun(1:38);
Vis = L_sun(39:78);
IR = L_sun(79:300);
UV_Vis_IR_fig = openfig('SolarIrradiance.fig');
hold on
ar = area(lambda(1:38), UV);
ar.FaceColor = 'magenta';
ar2 = area(lambda(39:78), Vis);
ar2.FaceColor = 'green';
ar3 = area(lambda(79:300), IR);
ar3.FaceColor = 'red';
hold off
legend('L_s_u_n', 'UV', 'Vis', 'IR')
print('UV_Vis_IR.tif', '-dpng', '-r600')
saveas(gcf, 'UV_Vis_IR.fig')
%%
% Part 3.
astmg173_table = xlsread('ASTMG173.xlsx');
Wave_Length = astmg173_table(1:2002,1);
AM_0 = astmg173_table(1:2002,2);
AM_15G = astmg173_table(1:2002,3);
AM_15D = astmg173_table(1:2002,4);
PowerDensity_AM0 = astmg173_table(:,1).*astmg173_table(:,2);
PowerDensity_AM15G = astmg173_table(:,1).*astmg173_table(:,3);
PowerDensity_AM15D = astmg173_table(:,1).*astmg173_table(:,4);
openfig('SolarIrradiance.fig')
hold on
2 个评论
dpb
2019-12-15
I get two figures but then
Error using xlsread (line 139)
XLSREAD unable to open file 'ASTMG173.xlsx'.
File 'C:\Users\...\Documents\MATLAB\Work\ASTMG173.xlsx' not found.
>>
Can't do anything really w/o the other data other than just put some additional random data onto the existing figure.
A Q? is why aren't you just continuing to add to the desired axis until you've got it complete as desired? Why go to the trouble of saving/loading a .fig file and trying to modify it instead? Looks like you've generated all the data here; not like you don't have something that's needed that has to come from external source.
Another Q? is what's the need for symbolic variables? Don't have here so commented out but there's nothing that seems to need in code given.
回答(1 个)
Walter Roberson
2019-12-16
fig = openfig('SolarIrradiance.fig');
existing_line = findobj(fig, 'type', 'line');
ax = ancestor(existing_line, 'axes');
lambda = existing_line.XData;
hold(ax, 'on');
plot(ax, lambda, AM_0, 'DisplayName', 'AM 0' );
plot(ax, lambda, AM_15G, 'DisplayName', 'AM 15 G');
plot(ax, lamda, AM_15D, 'DisplayName', 'AM 15 D');
hold(ax, 'off');
drawnow();
saveas(fig, 'SolarIrradiance.fig');
4 个评论
Walter Roberson
2019-12-16
Okay, for any given row of astmg173_table column 2, how do you know what the corresponding lambda value is for it?
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Directed Graphs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!