Matlab GUI Edit Box - disable editing but must enable selection - matlab-guide

I have a GUI wherein I need a box which will be contain the path of a particular file. I want the text to be selectable by the user but unavailable for editing. Please help me find the answer.
Thank you in advance.

set(editTextHandle,'Enable','Inactive');
By doing so user can't edit the text.

I don't know if there is a way to prevent user from editing, but you can achieve similar result by letting the callback of the edit to change the text back to its original result if user attempts to change it.
For example, you have one pushbutton that lets you choose file, and an edit text box to display filepath:
function loadfile_Callback(hObject, eventdata, handles)
[fileName, pathName] = uigetfile;
handles.fullPath = fullfile(pathName,fileName);
set(handles.edit1,'String',handles.fullPath);
guidata(hObject,handles);
function edit1_Callback(hObject, evendata, handles)
set(hObject, 'String', handles.fullPath);
guidata(hObject,handles);

Related

MATLAB GUI: How do I turn off a push button when a text box is empty?..... Also, how can I produce error message when wrong file type is opened?

I am making a GUI in Matlab (I am a newbie to this) and I am stuck on two things:
1) I would like to prevent the user from selecting a file type other than .wav. I have managed to get the open dialog box to display only .wav files but that doesn't stop them selecting all files and opening another file type. This breaks the rest of my GUI. How can I defend against this?
2) I would like to prevent my 'Compute' push button being selectable when a certain text box is empty. How can I do this? I have tried the following but it doesn't seem to work:
p = get(handles.textbox,'String');
if isempty(p)
set(handles.compute, 'enable', 'off');
else
set(handles.compute, 'enable', 'on');
end
I would really appreciate some help.
Thank you very much
Best regards
1) you can throw an error and reset the selection if the file type doesn't have the extension '.wav'. Check the file name extension using the fileparts command.
2) Ensure that (a) if the textbox starts out empty, the button starts out with 'enable' set to 'off' and (b) your logic of testing the text box is inside the text box's callback. If you're setting the contents of the textbox from some other function, then the textbox's callback is not normally called. In that case, you should manually call the textbox's callback within that other function after setting the textbox's string, like:
set(handles.textbox, 'string', 'some_file.wav');
textbox_Callback(handles.textbox, eventdata, handles);

How to retrieve a mean number into matlab GUI from cell string?

I am building a matlab GUI to retrieve an average PnL number from a 1047*1 double cell string called pnl_P1 into edit text window called (function Average_PnL_Pair_1_Callback(hObject, eventdata, handles)). What is the simplest or very simple way to do this?
Do you want mean(cellfun(#str2double, pnl_P1))?
If I understand your problem correctly I'd do the following.
Do not store numbers in cell string array, but if you must, use mean(cell2mat(pnl_P1)) to get the mean value. Create a value under handles so you can reach your pnl_P1 vector from anywhere.
handles.pnl_P1 = pnl_P1;
Make sure you always update your handles after each function in your GUI. It is strongly recommended.
% Update handles structure
guidata(hObject, handles);
Insert value into edit box:
set(handles.edit1,'String',mean(cell2mat(handles.pnl_P1)));
handles.edit1 is the tag handle for the edit box you want to update.
What is the tag for your edit box?
Simple: in guide right-click on your edit box, select properties inspector, scroll down to Tag. If it says edit1 then use handles.edit1 and so on.
If you are new to Matlab GUIs I recommend this. They have stopped updating it but it's a great learning source.
I hope this helps.

jqgrid disable input and change text color in IE

Is there a way in IE to disable cell input inside grid and change it's color (so it won't be gray)?
Or Is there another way to disable an input - and not by changing it to "readonly"?
UPDATE:
I'm using inline editing , and my cell input is a regular simple input (editable:true, edittype:'text'). I want this input to be disabled but to changed it's text color to black when it is disabled.
Thank's In Advance.
The answer how to change the editable attribute temporary for some column before stating of editRow. In the way no input element will be created and you will not have toe problem which you try to solve.

In matlab, how do you save a figure as an image in the same way as using "Save As..." in the figure window?

When saving a figure, what function does Matlab use? For example, when a user selects File > Save As... and then selects .png or another image format, what is going on behind the scenes?
I am asking because I am trying to automate saving, but when I use saveas or print, the resulting image is really pixelated. However, the image looks really good when I save the figure using the method described above.
What method should I use to save my figure from the command line? The actual method that the figure window uses would work, but if you guys have better solutions, I'd appricate it!
The callback for the "Save As..." menu item invokes the function FILEMENUFCN with the first input argument being the handle of the figure the menu is in and the second input argument being the string 'FileSaveAs'. If you have the figure handle stored in the variable hFigure, then the following command should be equivalent to clicking the "Save As..." menu item in that figure window:
>> filemenufcn(hFigure,'FileSaveAs');
A few notes...
The function FILEMENUFCN is only partially documented. You can do help filemenufcn in the command window, but there is no entry for it in the online documentation. In MATLAB 2009a, the function can be found in the following folder:
C:\Program Files\MATLAB\R2009a\toolbox\matlab\uitools\filemenufcn.m
Looking through the function code, it appears that it ultimately calls either the function SAVEAS for .fig files or the function HGEXPORT (with additional input arguments) for other file types.
I was able to hunt down the callback for the "Save As..." menu item by searching through the children of the figure window and its menus. You can do this yourself by setting the root property 'ShowHiddenHandles' to 'on' and then traversing through the 'Children' properties of the figure window and its menus using the GET command. An alternative is to use the FINDALL command, assuming you know some properties of the objects you are looking for. For example, this will find the handle to the "File" menu for the current figure window:
>> hFileMenu = findall(gcf,'Label','&File');
And this will find the handle to the "Save As..." menu item and display its callback:
>> hSaveAs = findall(hFileMenu,'Label','Save &As...');
>> get(hSaveAs,'Callback')
ans =
filemenufcn(gcbf,'FileSaveAs')
I don't know about you, but for me the saved image looks nice.
Code example:
... create some figure ...
saveas(gcf, 'some_figure.png');
To set a user specified resolution use:
print(gcf,'some_figure','-dpng','-rSOMENUMBER')
where SOMENUMBERis a parameter used for the resolution.
The final resolution is (SOMENUMBER*8) x (SOMENUMBER*6)

How do I choose an input using a GUI/explorer window in a MATLAB program?

I actually have 2 queries:
How do I display the data of a variable in a msgbox? In other words, if I have dist=3765 at the end of my program and I want to display it in a msgbox, how do I do it?
I want the user to select an input file (suppose an image) from a folder in my MATLAB program using an explorer window at runtime. How do I code that in MATLAB, or is there an existing function available for it?
You should check out these MathWorks blog posts (here and here) from Ken and Mike discussing all of the dialog boxes that you can use in MATLAB. The specific dialog boxes that address the needs listed in your question would be:
MSGBOX, which will display a message. You first have to create a string to use as a message. For example, if you have a variable dist that stores an integer value you want to display, you can do the following (using the function INT2STR):
hMessage = msgbox(['dist = ' int2str(dist)]);
UIGETFILE, which opens a dialog box for selecting a file and returns the file name and path selected. For example, the following opens up a dialog box to select a MATLAB file (*.m, *.fig, *.mat, etc.) from the current directory:
[fileName,filePath] = uigetfile();

Resources