Hi everyone, i was wondering if there is a way for a scope i use in a simulink model to automaticaly autoscale. Maybe from adding a code to its startfunction???

 Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 18 de En. de 2012

1 voto

Hi Raldi,
assuming the scope blocks are open, the following piece of code does the autoscaling for you:
% find all scope blocks as MATLAB figures:
set(0, 'showhiddenhandles', 'on')
scope = findobj(0, 'Tag', 'SIMULINK_SIMSCOPE_FIGURE');
for i=1:length(scope)
% this is the callback of the "autoscale" button:
simscope('ScopeBar', 'ActionIcon', 'Find', scope(i))
end
set(0, 'showhiddenhandles', 'off')
Titus

5 comentarios

Raldi
Raldi el 18 de En. de 2012
should i add this in the Stopfunction inside tho model or in the GUI?
Raldi
Raldi el 18 de En. de 2012
i am asking because when i try to run it as an m file it sais
Error using Simulink.scopes.Util.SimpleSimStatus (line 2589)
Invalid Simulink object handle
Raldi
Raldi el 18 de En. de 2012
Sorry my bad it is working!!! Thanks Titus...
Scott Rauscher
Scott Rauscher el 18 de En. de 2013
Where did you implement this Raldi? I'm not sure how to use the code that Titus supplied. I tried adding it in a Matlab Function that runs in the Simulink model, but that didn't work
I also tried just running the code in Matlab afterwards and that did nothing. What did you do?
Ignacio
Ignacio el 18 de Sept. de 2013
To make the autoscale function automatically i created a matlab function with the code above. The code will be executed each certain period of time. In my case 3 seconds, i did it with this function and the block clock of Simulink. the function that i have created is this one: -------- function u=scope(y) % find all scope blocks as MATLAB figures: u=0; z=mod(y,3)==0 if(z==1) set(0, 'showhiddenhandles', 'on') scope = findobj(0, 'Tag', 'SIMULINK_SIMSCOPE_FIGURE'); for i=1:length(scope) % this is the callback of the "autoscale" button: simscope('ScopeBar', 'ActionIcon', 'Find', scope(i)) end set(0, 'showhiddenhandles', 'off') end
end ----------- Then, in the clock block i selected 1000 as decimation and i use this code in a "interpreted Matlab function" block just writting "scope" in the label "Matlab function". I drive the output of this function to a scope but this output is not really interesting.
best regards

Iniciar sesión para comentar.

Más respuestas (5)

Ilham Hardy
Ilham Hardy el 17 de En. de 2012

0 votos

By clicking the binocular button on the scope, perhaps?

2 comentarios

Raldi
Raldi el 17 de En. de 2012
well i said automatically so this excludes clicking stuff :)
Mandip Regmi
Mandip Regmi el 20 de Mayo de 2020
I did not find the binocular button too

Iniciar sesión para comentar.

TAB
TAB el 18 de En. de 2012

0 votos

Add below piece of code in your 'StopFcn' callback function. When the simulation is completed, it will open and autoscale all the scopes in the model.
[EDITED TO WORK FOR MULTIPLE INPUT SCOPE]
bh=find_system(gcs,'FindAll','on','BlockType','Scope');
for x=1:length(bh) %close all scope
set_param(bh(x),'Open','off');
end
for x=1:length(bh)
set_param(bh(x),'Open','on');
fh=gcf;
AxesInScope = findall(fh,'type','axes');
for y=1:length(AxesInScope)
set(fh,'CurrentAxes',AxesInScope(y));
xlim('auto');
ylim('auto');
end
end

6 comentarios

Raldi
Raldi el 18 de En. de 2012
it doesnt seem to be working, where exactly should i insert this code. I have a gui that can interact with the model if that helps.
Ilham Hardy
Ilham Hardy el 18 de En. de 2012
On your simulink model goto: File>>Model properties>>Callbacks>>StopFcn
TAB
TAB el 18 de En. de 2012
You can insert this code in the 'StopFcn' callback function of model.
[1] Open Your Model
[2] Goto File -> Model Properties
[3] Click on callback Tab in Model Properties window
[4] Select 'StopFun' on left side of window
[5] Paste the above code in Text box.
The code will be executed when the simulation stops (after completion or using stop button).
Once simulation is stoped, all the scopes in model will be opened and autoscaled automatically.
Raldi
Raldi el 18 de En. de 2012
Still, it wont autoscale it. It only opens a figure in the end of the simulation. Does it have any relevance that i am using a scope with two inputs?
Raldi
Raldi el 18 de En. de 2012
What if i somehow used set Ymin = min(inout) Ymax = max(inout)... is this possible?
TAB
TAB el 18 de En. de 2012
As your scope is reading 2 inputs, previous code was autoscaling only one graph keeping other as it is.
I have updated the code so that it can work for multiple input scopes.

Iniciar sesión para comentar.

Andreas Goser
Andreas Goser el 18 de En. de 2012

0 votos

Typically, when users describe this, they are happy with the Time Scope Block from DSP System Toolbox. Here is the link to the documentation.
Especially, as Raldi is working at a university in the field of Signal Processing, this product should be available. Note that previous versions used different names like Signal Processing Blockset or DSP Blockset.

4 comentarios

Raldi
Raldi el 18 de En. de 2012
Thank you Andrea but still the time scope is not what i exatly need, you see i have two main signals that need to be shown in the same scope.
Andreas Goser
Andreas Goser el 18 de En. de 2012
Well, then you might need to write your own block (s-function).
Raldi
Raldi el 18 de En. de 2012
Yeah i figured you might say that. The thing is that i am not sure how to do that.
Raldi
Raldi el 18 de En. de 2012
i think there is another way, ill try to change its YLim throygh my gui and update it.

Iniciar sesión para comentar.

Mingli ZHU
Mingli ZHU el 22 de Abr. de 2021
Editada: Mingli ZHU el 22 de Abr. de 2021

0 votos

set(0, 'showhiddenhandles', 'on')
%current graphic object
scope=gcf;
%find Autoscale object
scale=findobj(gcf, 'Tag', 'uimgr.uisplittool_Autoscale');
%click this object
feval(get(scale,'Callback'),scale,[]);
%find PrintToFigure Menu
fig=findobj(gcf, 'Tag', 'uimgr.uimenu_PrintToFigure');
%Click this Menu
feval(get(fig,'Callback'),fig,[]);
set(0, 'showhiddenhandles', 'off')
Jessy Mathault
Jessy Mathault el 27 de Ag. de 2021

0 votos

This function:
simscope('ScopeBar', 'ActionIcon', 'Find', scope(i))
Doesn't seem to be supported anymore in MATLAB 2020b.
This seems to work:
allAxes = findall(gcf,'type','axes');
for x = 1:numel(allAxes)
axis(allAxes(x), 'auto y');
axis(allAxes(x), 'auto x');
end

Categorías

Productos

Preguntada:

el 17 de En. de 2012

Respondida:

el 27 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by