I am currently developing a complex MATLAB application. I am trying to save figures (created within its UI) by using the getframe function. This works fine, and saves the figure as intended. However, the UI 'blanks' after every use. The window remains but becomes a uniform white rectangle. Mousing over features in the UI makes them appear again (like a fog-of-war). Adding a refresh statement did not help.
Why does this happen? How do i make it stop?
Irritatingly this doesn't happen in 2018a, but the code is in 2014b, which is problematic (something I discovered after being pleased at my cool fix :( ).
Unfortunately posting code is not feasible because I do not have permission to share it.
OK after much research I've been unable to find a direct solution. But I have implemented an indirect solution.
refresh
was not working so I implemented a manual, forced redraw. I.e. I jitter the screen after getframe by 1 pixel, which redraws the window.
figpos = fig.Position;
jitter = figpos;
jitter(3) = jitter(3) + 1;
jitter(4) = jitter(4) + 1;
set(fig,'Position',jitter);
set(fig,'Position',figpos);
It's probably unnecessary to expand, and contract, both the width and height of the window, but it does the job fine.
Related
I have a zest(1.5.0) graphViewer which is quite large as a result scrollbar appears in the composite.
Now when I am trying to export this graph as a png I am getting only the visible portion of the graph.Region beyond the scrollbars is not available in the image.
Image image = new Image(PlatformUI.getWorkbench().getDisplay(), composite.getBounds().width, composite.getBounds().height);
ImageLoader loader = new ImageLoader();
GC gc = new GC(image);
composite.print(gc);
gc.dispose();
loader.data = new ImageData[]{image.getImageData()};
loader.save("c:/raja/graph.png", SWT.IMAGE_PNG);
If I use graphViewer object it gives nodes collapsed on the top left corner
GC gc = new GC(viewer.getGraphControl());
Rectangle bounds = viewer.getGraphControl().getBounds();
Image image = new Image(viewer.getGraphControl().getDisplay(), bounds);
**<Rest same as above code>**
I need to get a single image with complete graph in it.Is there a way to achieve this.
I think animation could be causing the clustering of nodes in second approach.Is there a way to turn it off (I tried setting nodeStyle to ZestStyle.No_Animation_Layout but it did not help the cause).
Printing/drawing into the image is no different from printing/drawing on the display. You need to actually draw everything, what should be displayed. We had similar requirement for printing Ghantt Chart. You can download the source code and check how printing is supported there.
The idea is that you need to control drawable area and draw all the objects one by one there and then start drawing next page. I'd say it is not the easiest task, as it usually requires lots of calculations to support different printing settings.
In your case I don't know if you have control over the source code to support such functionality, so may be it would be possible to emulate it by programmatically scrolling your graph and drawing it at the same time, using composite.print(gc). However, this might introduce bad user experience.
There are also some frameworks, like PaperClips to make your printing little bit easier. There are also some swing libraries, which could be integrated into your Eclipse RCP. Also, please see this SO question for more details.
Hope that this could give you some ideas.
Context
Using the GUI Layout toolbox I have created an interface which basically is divided in two parts:
A toolbar area where the user selects the way he want to see data
A preview area to display data upon selected mode in the toolbar
For the preview area I used a uietxras.CardPanel object to switch between the view modes.
Problem
After some investigations, I discovered that if I display things in 3D (or 2D) in one of the preview card using surf (or pcolor) then it alters the display in the second card. If I display data in 1D only using plot commands I have not issue!
The issue I have when using pcolor/surf in one of the preview card:
Titles and labels seem to overlay in Preview 1
Axis borders are not displayed correctly in preview 2
Legend borders (when displayed) are altered also
If I only use plot commands in both preview modes I have no issue at all and cards are switching nicely.
Test case
My real code is really long, I have thus reduced it to the minimum so you can reproduce the issue:
https://gist.github.com/CitizenInsane/54f3c1eba2293d0e5264#file-guilayoutbug-m
Simply run the code and check the checkbox "Do 3D plot in preview 1" to see the issue happening when switching between the two preview modes:
Notes
As far I know, I'm using latest version of the GUI Layout toolbox (1.17).
I'm using R2013b for Matlab
I came across this issue as well. I'm afraid I never quite worked out what the cause was exactly, and it didn't appear in a very consistent way. The issue seems to be that plots on non-selected cards are not hidden properly, and get overlaid just behind and around the edges of the plots on the selected card.
I would encourage you to raise the issue with the authors of GUI Layout Toolbox via the comments on the toolbox's page at MATLAB Central, as I do think it's a bug.
Nevertheless, the reason I never followed it up myself is that I found a fairly straightforward workaround, which may also work for you. Each time the selected card is changed, I ran a simple function that deleted all children of all cards, and then re-plotted whatever I wanted on the selected card. It seemed a bit annoying to have to do that, but it worked, and removed any of the display issues you've come across.
Ok got it, the issue has nothing to do with CardPanel themselves, it is linked to the renderer of the figure.
Trying simple code below:
figure(42);
subplot(1,2,1);
plot(rand(1,12));
subplot(1,2,2);
peaks;
shading flat;
If the figure's renderer is set to 'OpenGL' (the default) ==> there are some glitches:
If the figure's renderer is set to 'zbuffer' ==> there is no glitch:
Setting the renderer to 'zbuffer' fixes the problem.
NB: Maybe OpenGL rendering can be fixed by fine tuning graphic card acceleration settings, but I don't know ... I issued opengl software and opengl hardware commands in Matlab and software rendering is worst than hardware rendering on my machine.
EDIT: Side notes
Transparency effects are only available if the renderer is set to 'openGL'. It is thus not possible to visualize at the same time both 1D and transparent-3D data without glitches (at least with hg version 1 in R2013b).
HG2 has no issue:
I have been searching for a long time and have yet to find a tutorial/answer so I am posting the question here. How can I render a continuous signal within Simulink as a bar graph? The bar graph should be behaving similarly as the native default scope block within Simulink. I.e.: the graph changes in real-time while the signal is running. The same functionality (or close to it) as scope, but in a bar graph format. Any help or directions are appreciated.
There is a Floating Bar Plot in the Simulink Extras->Additional Sinks library.
However, it has very limited functionality.
The best way to do this is to write an (m-code) S-Function. Although not difficult, it's not going to be trivial to do properly. Within the S-Function you'll need to do things like
initialize a figure window and an axes on it, and open the figure if it is still open (from a previous simulation).
update the plot (efficiently, and most likely using low level functions, not the bar function itself)
check that the user hasn't closed the figure, and only plot data if it hasn't (or reopen the figure if it has been closed).
You will most likely also need to use some of the block callbacks to do the right thing if the block is deleted (e.g. delete the figure too, if it's still open), copied, etc.
I have created a basic MATLAB UI (without using GUIDE). I basically have a bunch of panels for various things, (sliders, axes, text boxes, etc).
The one thing I would like to do though, it make it so that they scale properly, when I resize the figure. Right now, I painstakingly have to make a re-scale function for every button, panel, sub-panel, etc etc to make it rescale correctly.
Is there an easy way to simply automate the re-scaling here?
Thanks.
Use the GUI Layout Toolbox from the MATLAB File Exchange. I haven't personally used dynamic resizing functionality, but that's one benefit of using this package.
It functions much like using uicontrols, except you can't use the inspect tool on these objects.
EDIT: If you're looking only to do resizing when the figure itself is resized, set the Units property for all your uicontrols to normalized.
You could also use the builtin, but undocumented uigridcontainer and uiflowcontainer.
They have the benefit of e.g. allowing to set contraints, such that e.g. your pushbuttons don't get increased in size, when the full figure does. Check the link for some examples:
http://undocumentedmatlab.com/blog/matlab-layout-managers-uicontainer-and-relatives/
How can I integrate a Scrollwheel into my application?
I'm currently using Sliders but have found them to be sometimes difficult to control exactly (for example with a linear scale from 0% to 100%). I guess they weren't designed for that purpose and are meant to be used for cases where not pitch perfect control is ok (Volume Control and the likes). However, I really need an exact way of inputting data (other than TextFields, they won't work in my case).
I figured that a Scrollwheel kind of UI Element would be perfect for me. Are there any opensourced Scrollwheels available that would fit my needs?
Horizontal, just like Sliders
Variable Start and End Values
Variable Scale
Small in height
Pretty :)
I tried using the Picker but that didn't work for me since it shows it's values inside of it, which makes it both big and not pretty to look at when used multiple times inside of one View.
If there's nothing available that fulfills my needs (described above) could someone please give me a hint on how to start effectively with creating such a UI element? Thanks!
I've finally found something which fits my needs :)
OBSlider, a subclass of UISlider which allows variable scrubbing speeds – it imitates the behavior seen while scrubbing in iPod.app.
Fulfills all my needs:
Horizontal
Variable Start and End Values
Variable Scale
Small in height
Pretty :)