# Dynamically updating density graphs with values from slider in MATLAB

I have two complex data matrices $A,B$. I can combine them using functions $f(A,B,x,y),g(A,B,x,y)$. For simplicity, say my functions are $f(A,B,x,y)=xA+yB$ and $g(A,B,x,y)=xA-yB$. I would like to graph the functions $|f(A,B,x,y)|$, $\arg\left(f(A,B,x,y)\vphantom{^2}\right)$, $|g(A,B,x,y)|$ and $\arg\left(g(A,B,x,y)\vphantom{^2}\right)$ in MATLAB and have them dynamically update as I change the values of $x$ and $y$ using sliders. Is this possible? A couple of hours of googling and playing around with my code taught me a few things about sliders but not how to combine them with graphs.

So far, I've managed to place the four graphs in a single figure, but I have no idea how to include the sliders in the figure, have them update the values of $x$ and $y$ and have the graphs respond accordingly. Here's my code:

figure;
h=[];
h(1)=subplot(3,2,1);
h(2)=subplot(3,2,2);
h(3)=subplot(3,2,3);
h(4)=subplot(3,2,4);
h(5)=subplot(3,2,5);
h(6)=subplot(3,2,6);
image(abs(xA+yB),'CDataMapping','scaled','Parent',h(1)),colormap(autumn),set(gcf,'name','linear combination...','numbertitle','off'),xlabel(''),ylabel('');
image(angle(xA+yB),'CDataMapping','scaled','Parent',h(2)),colormap(autumn),set(gcf,'name','linear combination...','numbertitle','off'),xlabel(''),ylabel('');
image(abs(xA-yB),'CDataMapping','scaled','Parent',h(3)),colormap(autumn),set(gcf,'name','linear combination...','numbertitle','off'),xlabel(''),ylabel('');
image(angle(xA-yB),'CDataMapping','scaled','Parent',h(4)),colormap(autumn),set(gcf,'name','linear combination...','numbertitle','off'),xlabel(''),ylabel('');


I've included a third row of subplots to place the sliders in, but if that isn't the correct way to do it I can simply remove h(5) and h(6) and change all the subplot(3,2,...)s to subplot(2,2,...)s.

Thanks!

• I think stackoverflow is a more appropriate site to post this question. Aug 2, 2018 at 17:52
• Thanks. I've posted it there.
– Rain
Aug 2, 2018 at 19:07
• You´re welcome and good luck. Aug 2, 2018 at 19:10