Open Simulink model with set window size and position
10 次查看(过去 30 天)
显示 更早的评论
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
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
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 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!