Filter löschen
Filter löschen

Why does my plot shrink?

5 Ansichten (letzte 30 Tage)
Andy
Andy am 28 Feb. 2024
Beantwortet: Andy am 1 Mär. 2024
Hi,
I was wondering if any may be able to help? My plot keeps shrinking when the FOR loop has finished.
It should look like this,
and does whilst it is updated from the FOR loop, but as soon as the loop has finished it looks like this
The code for the imagesc plot is as follows:
within the app
% Define axis to plot
axis(app.UIAxes,'image');
app.ax = app.UIAxes;
% Call function FDTD
[app.E2,app.V2] = fdtd_time_reversal(app.X, app.Y, app.del, app.dt, app.send, app.arraystart, app.elements, app.receiver , 1, 1, -app.depth, app.offset + app.depth, app.media, app.er, app.ax);
imagesc(app.UIAxes,app.E2)
axis(app.UIAxes, 'image')
xlim(app.UIAxes, 'tight')
ylim(app.UIAxes, 'tight')
drawnow
and within the function, where a call is made to another function first.
% 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));
E1=E;
E2=E;
colormap(ax, jet)
% mesh(ax, E)
imagesc(ax, E)
caxis(ax, [-100 100])
axis(ax,'image')
xlim(ax, 'tight')
ylim(ax, 'tight')
drawnow % This command will tell MATLAB to draw this frame before moving on
Hoping someone may know.
Kind regards,
Andy
  1 Kommentar
Chunru
Chunru am 28 Feb. 2024
You may want to try the following (or combinations of them):
axis(ax, "ij")
axis(ax, "normal")

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Andy
Andy am 1 Mär. 2024
I thought I would share the following answer from Mathworks support that resolved the problem, in case someone else has a similar issue.
When you declare a function in MATLAB, you write a function signature that declares the number of inputs/outputs, and the order in which the function will expect to receive/return them. For example, the first line of "fdtd_time_reversal" defines a function which returns four outputs in the order, "V1", "V2", "E1", then "E2":
[V1,V2,E1,E2] = fdtd_time_reversal(X, Y, del, dt, signal, receiver, elements, arraystart, arrayspace, rarrayspace, depth, offset, media, ER, ax)
When you make calls to this function from within the app, it should obey this function signature, and provide inputs and assign outputs in that same order.
When you call the "fdtd_time_reversal" function on like 244 of your app, you do so with the following line, and therefore the value assigned to "app.E1" is not "E1", but "V1" as this is the first output returned in the function signature:
[app.E1,app.V1] = fdtd_time_reversal(app.X, app.Y, app.del, app.dt, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);
The array "V1" has far fewer rows than "E1", so when you plot "app.E1" after the simulation on line 246, you are actually seeing an image of the smaller "V1" array:
imagesc(app.UIAxes,app.E1)
Line 244 should be updated as below, where I have used the tilde "~" character to indicate that I do not want to assign an output declared in the function signature:
[app.V1, ~, app.E1, ~] = fdtd_time_reversal(app.X, app.Y, app.del, app.dt, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);

Weitere Antworten (1)

Andy
Andy am 28 Feb. 2024
Hi Chunru,
Thank you for your reply. Both your solutions has stopped the plot from shrinking, however now the Y axis is rescaled, which interferes with the results! Very strange. I wonder if you have any ideas?
Best regards,
Andy
  1 Kommentar
Andy
Andy am 28 Feb. 2024
Bearbeitet: Andy am 28 Feb. 2024
Intrestingly, if I call each part of the function individually (which makes the image plot run twice), the plot doesn't shrink and the results are what they should be. Could the problem be the function returning both the app.E1 and app.V1 in one function call?
[app.E1] = fdtd_time_reversal(app.X, app.Y, app.del, app.dt, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);
imagesc(app.UIAxes,app.E1)
% mesh(app.UIAxes,app.E1)
% axis(app.UIAxes, 'image')
axis(app.UIAxes, 'normal')
xlim(app.UIAxes, 'tight')
ylim(app.UIAxes, 'tight')
drawnow
[app.V1] = fdtd_time_reversal(app.X, app.Y, app.del, app.dt, app.signal, app.receiver, app.elements, 1, app.arrayspace, 1, app.depth, app.offset, app.media, app.er, app.ax);
plot(app.UIAxes3,1:length(app.V1),app.V1)
title(app.UIAxes3,'Recorded signal at array elements')

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by