Displaying Signals in Simulink - matlab

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.

Related

MATLAB 2014b getframe causes UI to 'blank'

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.

Calling GUI more than once

I am developing a complex program in MATLAB R2013a to evaluate EEG and other data recorded from animals. I have a main GUI with a menu bar and two panels on which up to 16-16 axes can be shown. I created two GUIs with GUIDE. One is used to set the sampling rate, the number of recorded channels, etc., when I open a new data file. The other GUI is used to set how many graphs should be drawn in the main GUI, which recorded channel should be shown, is filtering necessary or not, etc. To set all these things takes about 400 controls (popuplists, checkboxes, etc.)
I call these GUIs several times from the main GUI. The first GUI keeps all changes that I made during the previous call, while the other GUI is reset to the initial state whenever I call it. Of course, I could store the values of these 400 controls, and somehow restore them to the previous state, but it would be very tedious.
Can somebody tell me why the two GUIs behave differently? In my view, it is not unusual that a GUI is called more than once from a program, and it also seems natural that the user only wants to change a few settings and not rewrite everything.

Matlab GUI: how to add docked figure group?

I would like to be able to add a figure container to a matlab gui...
In core matlab, with a docked window style you can have a large number of plots stacked one behind the other, all within a figure container with a tabbed list along the side of the container that you can simply click to bring a particular figure to the front.
Is there a way to have this sort of figure container in a matlab gui?
Use Ben Tordoff's GUI Layout Toolbox. It contains functionality for tabbed panels and dockable/undockable panels that can contain figures, and many other capabilities that you'll find very useful if you are creating GUIs in MATLAB.
You will need to organize your GUI code slightly differently, but it's not hard to learn and there are great examples in the documentation.
It's not really possible to do what you're describing with just regular MATLAB: figures will just dock into the main MATLAB desktop, not into your GUI specifically. The best way (without GUI Layout Toolbox) would probably be to fake a row of tabs using buttons next to each other, with callbacks on the buttons that deleted/hid one plot and drew/revealed another. There is a function uitab that does tabs, but before R2014b it's undocumented, and it's a bit of a pain anyway. Better all round to use GUI Layout Toolbox.
If you're open to play around with undocumented features, this can be done using the java objects behind the matlab figures, e.g. using a little tool from the fileexchange.
This will create a new dock group, just like MATLAB's container for figures, editor etc.

Make MATLAB panels automatically rescale. (Not using GUIDE)

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/

Continously Updating UIViews in Objective C

I am very new to Iphone programming with Objective-C but I have picked up pretty fast in the last 1 month.
I have an application that reads data from a .csv which I then use to plot a continous graph on the Iphone. The problem is that there are close to 84,000 data points ( a major requirement) and the current design I used with Quartz 2D has helped to make the required plots but it takes close to 3mins for the UIView to show the infinitely long plot I desire.
The solution I am looking for is this
I intend to use a function in normal C language to sequential access the file within a thread and pass it to the drawing function which will then update the screen as the data arrives so that the user has a feel of how the data is been plotted continously. The problem I have however is that the CGRECT drawing function and the setNEEDSDisplay would just take all the points at once and display on the UIView,
How do I update only specific point on the UIView as the data arrives without clearing the whole View
You'll want to use setNeedsDisplayInRect as described here:
Drawing incrementally in a UIView (iPhone)
Have you looked at using Core Plot?
http://code.google.com/p/core-plot/
It's a little hard to figure out, google for example uses. But it may be able to handle what you need through selective plotting of large data sets.