Skip to content

Instantly share code, notes, and snippets.

@jordanwesthoff
Last active August 29, 2015 14:15
Show Gist options
  • Select an option

  • Save jordanwesthoff/bdbe86a9caf34fc5e3bc to your computer and use it in GitHub Desktop.

Select an option

Save jordanwesthoff/bdbe86a9caf34fc5e3bc to your computer and use it in GitHub Desktop.
This is a test function called all_curves, which is a basic tutorial to plotting multiple curves on a single plot in MATLAB. This function plots lines based upon a given interval of temperatures and then analyzes them using the contained MATLAB function black_bodyf to analyze them using Planck's energy equation for black body emitter sources.
% MATLAB
function all_curves(floor_temp, ceil_temp)
% Interactive example and tutotial for plotting multiple lines on a Matlab
% figure using black_body representative temperatures.
% Function takes in two values, a low (floor) temperature and a high (ceil)
% temperature and plots lines incremented between them. The function then
% plots each plotted_line based on each increment and then scales automatically to
% fit the values.
% WARNING: This function used the Matlab dependancy function black_bodyf. (Contained below)
% Create a new figure for the lines to be plotted on.
figure;
%Set the size of the figure, as well as the position of the figure.
set( gcf, 'Position', [10 10 1024 768] );
% Preparation before the start of the loop:
% Assign the style of the plotted_line as well as the colors that are
% avalailable for use in the plot once the 'for loop' is triggered.
% Also create an index variable, idx to increment from while the loop
% runs.
lineStyles = '-:';
colors = 'rgbkcmy';
idx = 0;
% Initiate the for loop, plot a value for every temperature between
% 2000 and 10000 using a 2000 degree value increment.
for temp=[floor_temp:2000:ceil_temp]
% Assign a temporary variable based on the plot particulars and the
% index variable, idx
temporary_variable = mod( idx, length(lineStyles) );
plotted_line = lineStyles( temporary_variable + 1 );
temporary_variable = mod( idx, length(colors) );
clr = colors( temporary_variable + 1 );
% Set the response equal to the value generated by the Matlab
% function black_bodyf, a scientific calculator for Planckian
% radiation scenarios.
response = black_bodyf( temp );
% Plot the responses and define their line styles.
plot( response(1,:), response(2,:), [clr plotted_line], 'LineWidth', 2 );
hold on;
% Increment the temporary variable for the next iteration through
% the loop.
idx = idx + 1;
% Label the plot.
label = sprintf('T = %6d', temp);
allLabels{idx} = label;
end
% Put a legend on the plot:
legend( allLabels );
end
function response = black_bodyf( temp )
% PURPOSE
% Generates a standard curve for a input temperature based on a
% standard Blackbody emitter.
% Jordan Westhoff, RIT 2015
wl = [100:10:4000];
idx = 1;
% This is an example of the "set and correct" pattern.
% The default values are set to something that indicates
% 'wrong', and then they are corrected in the loop.
response = zeros(2,length(wl));
for wavelength = wl
value = planck_value(temp,wavelength);
response(1,idx) = wavelength;
response(2,idx) = value;
idx = idx + 1;
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment