フィルターのクリア

MATLAB resizing figures/Figures not displaying.

3 ビュー (過去 30 日間)
Daniel Bending
Daniel Bending 2021 年 2 月 19 日
コメント済み: Daniel Bending 2021 年 2 月 24 日
Hello all, I'm writing a program that fetches ODEs and variable values from some .txt model files, runs it all through ODE45 and displays the results. It also lets me change around my values. It's all a touch messy, I'll admit, but it works. I'm just trying to fix up my plots displaying the results. I currently have two methods of displaying them, one using the GUI Layout Toolbox and the other 'vanilla', so to speak. For the toolbox method a for loop produces a new axes each time that get stacked at the end:
How it looks before running:
And afterwards the button press with actual values for t and y:
Attempts to adjust "Position", regardless of the values I put in, result in:
A rundown of the (I believe) relavent code, this draws the plots:
function drawPlots(handle,num,names,t,y)
if (~exist('t', 'var'))
t = 0;
end
if (~exist('y', 'var'))
y = zeros(1,num);
end
for i = 1:num
a(i) = axes('Parent', handle);
plot(t,y(:,i),'Parent',a(i))
a(i).Title.String = [num2str(i)+ " - " + names(i)];
end
x_ax = ceil(sqrt(num));
y_ax = ceil(num/ceil(num/sqrt(num)));
set(handle, 'Widths', repmat(-1,1,x_ax), 'Heights', repmat(-1,1,y_ax));
end
This is called once initially without t and y just to produce the plots:
drawPlots(g,num,names)
Where g is given by:
g = uix.Grid('Parent', top );
After that it is called by a function intitated on the button press:
function onRunPress(PushButton,EventData)
handle = guidata(PushButton);
g = handle{4};
num = handle{5};
names = handle{6};
%Update var_val
%Generate new plot data
% - Handle plot inputs
%Inputs must be in the form of 1,2,3,4,..., n states
%Update plots
delete(g.Children);
drawPlots(g,num,names,t,y)
end
I removed the calculatory sections because all they do is grab the variable values, inputs and calculate t and y. Basically, I delete the previous plots and draw new ones with the updated t and y values.
Having not got very far fixing this method I attempted a new one just using default matlab panels:
function drawPlots(handle,num,names,t,y)
if (~exist('t', 'var'))
t = 0;
end
if (~exist('y', 'var'))
y = zeros(1,num);
end
x_ax = ceil(sqrt(num));
y_ax = ceil(num/ceil(num/sqrt(num)));
tl = tiledlayout(handle,y_ax,x_ax);
for i = 1:num
nexttile
plot(t,y(:,i))
title(num2str(i)+ " - " + names(i));
end
end
Where g is drawn by:
g = uipanel('Parent',top);
This, unfortunately, displays as:
However, when I minamise/maximise the window, the plots appear, in the correct spacing, at the correct size, for a split second. Of secondary note, it appears that:
delete(g.Children)
No longer functions and the tilelayout isn't being deleted and a second one is being stacked underneath it. Oh and visibility is true on the plots.
I would greatly appreciate any guidance! Thank you.
  3 件のコメント
Adam Danz
Adam Danz 2021 年 2 月 19 日
My bet is that somewhere in your code you'll see axis square (or setting the PlotBoxAspectRatio) along with setting the axis limits (xlim/ylim).
Daniel Bending
Daniel Bending 2021 年 2 月 24 日
Hi all, wanted to attempt more self-diagnosis before I directly posted my code/data. (Given its industry related its a bit iffy if I share things directly.) I wasn't able to diagnose the problem with the first plotting code, but I did work out the solution to multiplot, it's actually quite simple, intially I intiated the tiledlayout and then used a for loop to fill it in:
t1 = tiledlayout(handle,y_ax,x_ax);
for i = 1:num
nexttile
plot(t,y(:,i))
title(num2str(i)+ " - " + names(i));
end
The issue, I found, was that the itterative nexttile was making a new tiledlayout object under the main figure f. The fix was easy:
t1 = tiledlayout(handle,y_ax,x_ax);
for i = 1:num
nexttile(t1) %Declare the nexttile specifically for t1.
plot(t,y(:,i))
title(num2str(i)+ " - " + names(i));
end
Thank you both for commenting!

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

製品


リリース

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by