How to include plot in a function?

Hi everyone, basically this is the coding function (https://uk.mathworks.com/matlabcentral/fileexchange/880-mutual-average-information) that I've used to calculate the Average Mutual Information (AMI) in order to find the time delay. I want to plot time lags against AMI. similar to this picture. The problem now is i don't know how to include plotting coding in my fuction. Hope you guys can teach me yaa. thanks in advance!

4 comentarios

redroses
redroses el 19 de Abr. de 2020
I already add some code for plot. but only blank chart is displayed.
%% PLOT
if lag > 1
t = 0:lag;
plot(lag,v)
xlabel('Time Lag')
ylabel('AMI')
title('Average Mutual Information')
end
Tommy
Tommy el 19 de Abr. de 2020
Editada: Tommy el 19 de Abr. de 2020
What input arguments are you providing when you call this function?
(edit) My guess is the
if lag > 1
is causing issues, because it means that every element within lag needs to be greater than 1 for anything to be plotted. Is that intended?
redroses
redroses el 19 de Abr. de 2020
Editada: redroses el 19 de Abr. de 2020
hi mr tommy. first and foremost thanks for the reply ya. based on this coding https://uk.mathworks.com/matlabcentral/fileexchange/880-mutual-average-information , input for lag is 10 and for x value is like the one that I attached in the microsoft excel here. I've tried to remove if lag>1 like you suggested but only blank chart is displayed...
Tommy
Tommy el 19 de Abr. de 2020
If you are inputting a scalar value for lag, you will get a scalar for v. You are then plotting a single point.
To see this point, use
%% PLOT
if lag > 1
t = 0:lag;
plot(lag,v,'o')
xlabel('Time Lag')
ylabel('AMI')
title('Average Mutual Information')
end
I suspect that you should be using a vector for lag.

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Productos

Versión

R2019a

Preguntada:

el 19 de Abr. de 2020

Comentada:

el 19 de Abr. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by