Open Simulink model with set window size and position

조회 수: 19 (최근 30일)
Marlo Wegener
Marlo Wegener 2017년 9월 26일
댓글: Xavier Gross 2022년 9월 13일
Hello, I just created a small script for looking up the screen solution and then adjusting the Simulink location and view, it looks like this: % Sets the units to screen pixels set(0,'units','pixels')
% Gets the pixels of the screen pixels = get(0,'screensize');
% Create points for the window position point1 = round(pixels(3)/6); point2 = round(pixels(4)/6); point3 = pixels(3)-round(pixels(3)/6); point4 = pixels(4)-round(pixels(4)/6);
% Place the window in the center of the screen set_param(gcs,'location',[point1 point2 point3 point4])
% Center the content of the Simulink window set_param(gcs,'Zoomfactor','fit to view')
My thought was to place it in Model Properties/Callbacks/PostLoadFcn and then the window would appear at the defined location every time I open the model. Unfortunately that does not work and I wanted to ask if someone can tell me how I dot that?
  댓글 수: 2
Xavier Gross
Xavier Gross 2022년 8월 31일
Thanks for sharing your script!! It works well!
Do you find a way to make it work every time you open a model?
Or save it as default location for the following time you open it?
Xavier Gross
Xavier Gross 2022년 9월 13일
Got to the bottom of my issue. For some reasons, above code does not work when gcs is an harness model. I found that if you use the handle, it works:
ratio = 1/6;
set(0,'units','pixels');
pixels = get(0,'screensize');
point1 = round(pixels(3)*ratio);
point2 = round(pixels(4)*ratio);
point3 = pixels(3)-round(pixels(3)*ratio);
point4 = pixels(4)-round(pixels(4)*ratio);
h = get_param(gcs,'handle');
set_param(h,'location',[point1 point2 point3 point4]);
pause(0.2);
set_param(h,'Zoomfactor','fit to view');

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Modeling에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by