I want to write Greek characters and equations in textbox (Static Text) of Matlab GUI. Is it possible to write? I tried Latex $\eta { x }^{ 2 }+c$ but nothing changes. It displays the same.
Unfortunately it seems Matlab doesn't use the same text drawing methods on graphs, which support LaTeX, as it does on GUI elements. Here is a webpage explaining a workaround: http://undocumentedmatlab.com/blog/customizing-matlab-labels/
Basically, you will need to manually determine where you want the text to be on your GUI in terms of pixel position, and length, and rewrite your equation in HTML instead of LaTeX.
In the GUIDE interface for your GUI, you will need to click the "Editor" button on the toolbar menu, and find the section:
function initialize_gui(fig_handle, handles, isreset)
You'll want to insert your labeling code before the:
% Update handles structure
guidata(handles.figure1, handles);
Related
if I create a plot with some tabs in the titles and try saving that to a local pdf file (via print function), I get some hashtags instead of tabs in the pdf. This does not occur in the visible figure.
For example, I plotted the residuals of an approximant to the runge function on a grid:
plot(g, f(g) - runge(g));
title(sprintf('residuals,\t max_x(s-f) = %.3f', max(f(g)-runge(g))));
Then after some axes manipulation (grid, boxes, etc..) I execute
h = gcf;
set(h,'Units','Inches');
pos = get(h,'Position');
set(h,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(h,'data/runge_example.pdf','-dpdf','-r200')
close(h)
Is somebody aware of that behaviour or better able to found that as already solved than I am?
EDIT: Same behaviour with saveas and saving to eps. This does not happen with \n
EDIT2: I'm using Matlab Version R2017b (9.3.0.7...)
So, after a long discussion we figured out that we have no idea of how to use tabs in matlab titles in combination with latex mode.
To clarify: use math environments and escape tex directives, otherwise it will throw an error.
so
sprintf('residuals,\t $max_x(\\vert s-f\\vert) = %.3f$', max(f(g)-runge(g))));
will give you a nice string:
residuals, $max_x(\vert s-f\vert) = 0.264$
The problem is, that it really is a tab. And the matlab latex interpreter (don't know which one that uses, the system or an own) crashes on that. I copy-pasted that to a tex document and pdflatex ran fine on it (but not showing that much space unfortunately).
So, I came up with the following fix:
use the latex directive \quad or \qquad:
title(sprintf('residuals,\\quad $max_x(\\vert s-f\\vert) = %.3f$', max(abs(f(g)-runge(g)))));
This will give you more space than a normal space.
EDIT: For this to work you need the interpreter of matlab to be set to "latex" instead of the default "tex". Do this by changing the title to
title(title_string, 'Interpreter', 'latex')
or by setting (globally for that script)
set(groot, 'defaultTextInterpreter', 'latex')
I want to use GUI (or directly the Command Windows) in MATLAB, which displays text. The text contain a few highlighted parts (which are changed during runtime), like this:
Is there any way I can do something liek that with MATLAB?
For command window you could try cprintf.
For displaying in a GUI you can use html formatting - going down this route you may find str2html useful.
I'm writing a Gui with Guide. I have an Edit text box in it. Is it possible to write a vector instead of a single value in this box?
How to copy (to clipboard) only significant part of a plot in Matlab? Without that large gray margins Matlab loves so much?
Is it possible to populate clipboard from Matlab command line?
As far as programmatically populating the system clipboard with image data captured from a Matlab figure goes, you might try Yair Altman's, ScreenCatpture utility on the Matlab File Exchange:
screencapture('handle',gca,'target','clipboard');
It has a lot of options and will allow you to specify a region or an entire figure. It does require Java, i.e., it won't run in '-nojvm' mode. You can read more about it at Yair's Undocumented Matlab site.
Also, you can change the current figure's background color to white before copying it via:
set(gcf,'Color','w');
In the figure window, choose "edit" -> "Copy Figure".
It's equal to Ctrl+C on text, etc., but takes only the main part of the figure. So if you go to word, say, and press Ctrl+V, or RIght Click -> Paste, you will get only the main part of figure, without the gray margins you hate so much...
I am trying to learn GUI programming in matlab and for that purpose i am trying to create a simple multiplication calculator. I have done some programms in matlab without GUI but i am having difficulty in understanding GUI programming in Matlab. I have created the GUI but i dont know how to do the programming for that.
This is my GUI i made
EDIT TEXT 1; string= 0
EDIT TEXT 1; tag= edit1
EDIT TEXT 2; string= 0
EDIT TEXT 2; tag= edit2
STATIC TEXT 1; string= X
STATIC TEXT 1; tag= text3
STATIC TEXT 2; string= 0 (for showing results)
STATIC TEXT 2; tag= result
PUSHBUTTON; String= Calculate
PUSHBUTTON; tag=push_calc
i saved the given GUI in the name of "add" and created add.m . Can you tell me how to do programming for given gui.
The basic idea of matlab gui programming is the following:
Set up the figures
Enter the message loop
Both steps are taken care of by using the matlab gui editor (guide). The important thing is that you give control of the program flow over to the message loop. In order to get things done, you can tell the message loop to call a function whenever something happens.
In the gui editor, right click your pushbutton and select "View Callbacks -> Callback". This will automatically create such a function in you .m file where you can specify what happens when you push the button.
For a better understanding take a look at the Callback property of the pushbutton. Guide will have entered something like add('push_calc_Callback',hObject,eventdata,guidata(hObject)) which calls the main function (add) as a wrapper for your new callback function. You could have done that by yourself in the property editor or programmatically in the startup code.
I guess you want the following to happen:
Get the string values of edit1 and edit2
Convert the strings to numeric values
Perform the calculation
Set the string value of text3 to the string representation of the result
You can access the properties of the gui elements by using the handles available to you as the third function argument and the get and set functions. The handles structure is created by guide and the elements are named the same as the tag you specified.
In matlab code, this could look like this:
% --- Executes on button press in push_calc.
function push_calc_Callback(hObject, eventdata, handles)
% hObject handle to push_calc (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
x_string = get( handles.edit1, 'String');
y_string = get( handles.edit2, 'String');
x_numeric = str2num( x_string );
y_numeric = str2num( y_string );
result_numeric = x_numeric * y_numeric;
result_string = num2str( result_numeric );
set( handles.result, 'String', result_string);
Edit: The question is what is handles.edit1 and so on.
Whenever you want to do something with a widget like a button or a textbox, you have to be able to tell matlab exactly what widget you mean. Guide does a few things behind the scenes. One of them is to call uicontrol, which creates the widget and returns a random but unique number. This is a bit like a bank account number in the way that it is a handle to a resource that can be used to manipulate it. When you create a new pushbutton in guide and assign the tag "clickme" in the property editor, guide creates the pushbutton and stores the handle in a structure handles.clickme. That gives you an easy way to get the handle of any widget that you created if you can still remember what tag you assigned it.
Let's take the first line of the function:
x_string = get( handles.edit1, 'String');
That calls the function get with some number you should not care about as long as it the same number that matlab associates with the edit1 widget and a property name from the property editor, in this case 'String'. That would be the same as you clicking through all the window elements until the property editor shows a tag of 'edit1', and for that object you find the value for the property named 'String'.
The properties get updated automatically whenever you type in new text, move a slider, change the window size and so on. It works the other way around, too. If you modify the 'Position' property with set( handles.edit1, 'Position', [20 20 100 30]), then the widget is automatically moved and re-sized to the specified position.