Passing real time plot data from a Matlab function to App Designer for plotting
Show older comments
Hi,
Once again I find myself in a pickle that I'm hoping one of you guys may be able to help resolve.
I am using App Designer for the first time to contruct an app. From this app, I wish to call a function, bring the plot data into my app, and show the electromagnetic wave propagating in real time - just like it does in the figure when I run the Matlab function. Is this possible? At present, once I click on the 'Ping' button (see image below), the program runs then after a short while the final result is plotted (not filling the full box - but that is another problem)!
Best regards,
Andy
The code is as follows:

In my App I have the following to call the function fdtd_time_reversal
[E,frames] = fdtd_time_reversal(X,Y,app.signal,app.media);
imagesc(app.UIAxes2,E)
axis image
colormap(app.UIAxes,"jet");
app.frames
In my matlab function, I have the following
function [E,frames] = fdtd_time_reversal(X,Y,signal,media
% Defined parameters etc. to set up the FDTD solver
Then
% Start the main loop for FDTD calculations
%*****************************************************
% The outer loop enters each step, one at a time, while the inner loop inputs that
% step for each trace.
for j = 1:Nt,
for i = 1:tr;
% enter the signal from the last time step to the first (reversed in time)
%The Electric field is initiated by creating a magnetic loop
hx((i-1)*space+nb+start,offset+nb) = signal(i,j);
hy((i-1)*space+nb+start,offset+nb) = -signal(i,j);
hx((i-1)*space+nb+start,offset+nb+1) = -signal(i,j);
hy((i-1)*space+nb+start+1,offset+nb) = signal(i,j);
ezy((i-1)*space+nb+start,offset+nb)=0;
ezx((i-1)*space+nb+start,offset+nb)=0;
end;
% Advance the fields using code 'fdtd_andy'
[ezx,ezy,hx,hy] = fdtd_andy(ezx,ezy,hx,hy,alphaex,alphaey,alphamx,alphamy,betaex,betaey,betamx,betamy);
%The extra layers from the boundary conditions are removed
E=(ezx+ezy);
[a,b] = size(E);
E = E(33:(a-32), 33:(b-32));
%The desired signal is recorded
% V(1:array,j)=[E(rstart:rspace:rstart+(array-1)*rspace,offset+depth)];
%The current electric field is plotted and saved for the movie
% figure(2)
colormap(jet)
imagesc(E)
caxis([-100 100])
axis image
frames(j)=getframe;
end;
%######################################################################
3 Comments
Mario Malic
on 8 Feb 2024
Hi Andy,
I will comment on few things, without a lot of attention to it, but also due to my infamiliarity with imagesc and interactions with uiaxes components.
- In your UI, do I see is the uiaxes component, and you are trying to put inside it an imagesc output?
- As I see, your outer loop calculates the each step of your simulation. Within it, you should plot the electric field to the axis in the UI. You can do that if you add an optional argument, and that is handle for the uiaxis figure.
function [E,frames] = fdtd_time_reversal(X,Y,signal,media, hAxes)
% code
end
Andy
on 8 Feb 2024
Andy
on 9 Feb 2024
Accepted Answer
More Answers (0)
Categories
Find more on Graphics Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!