How do I create a function for returning a figure?

I have to create a function that returns a figure consisting of an average (as it is a singular output noted in the comment beside C I am not sure how to have MATLAB return the figure) Moreover, I'm not sure what would be a suitable X axis label (but that's not really important right now) Moreover, I'm not sure what would be a suitable x axis in general as it is a singular figure
Additionally, any advice on how I could have it return the figure in either red or orange?
Thank you

 Akzeptierte Antwort

Dyuman Joshi
Dyuman Joshi am 29 Nov. 2021
Example (replace data and labels accordingly)
function y
%xdata
x=0:0.1:50;
%ydata
y=sin(x);
figure(1) %initiate a figure
plot(x,y,'r') %use 'o' for orange
xlabel('Time');
ylabel('Sine curve');
title('Sin curve graph')
end

2 Kommentare

thank you!
I've tried to build a function as you described. The problem is only the data (plotted) shows in the main program. The changed axis, title and ledgend are missing. Even when I create a figure, to wich i assign the changes and give to the main program as a variable.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte

Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by