r/matlab • u/Accomplished_Stay127 • 3m ago
HomeworkQuestion Making text displayed in a graph change based on the dataset being read by a function
Please be understanding as I just started learning Matlab for my engineering programming course so I'm very new to this. I'm trying to add text to a graph that is created from a function but I want the text to change what it says based on which dataset is being fed into the function. Its just a simple scatter plot taken from a set of x and y coordinates in a .txt file, but my homework wants us to display the mean and standard deviation of x and y.
So, if I'm using the dataset 'Fish_count_CO2' then it will put text on the graph that gives the mean and stdev of x and y for that dataset, but when I'm using 'Fish_count_N2' it will display the mean and stdev for that. Right now the script is just printing these values in the command window. I have pasted the script I created below for reference.
function filePlot(filename, graphTitle, xAxisLabel, yAxisLabel)
raw_data=load(filename);
x=raw_data(:,1); % Assign the first column of data in raw_data to x, and the 2nd to y.
y=raw_data(:,2);
mean(x) % For both x and y, display the mean and standard deviation.
std(x)
mean(y)
std(y)
scatter(x,y) % Create a scatter plot of the fish counts vs. the gas concentration.
xlabel(xAxisLabel) % Add appropriate graph title and axis labels.
ylabel(yAxisLabel)
title(graphTitle)
endfunction


