Wednesday, 7 November 2018

MATLAB - Clear all Axes on button press in Pushbutton

% --- Executes on button press in pushbutton
function pushbutton_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
 


%Clear all Loaded Axes
cla(handles.axes1,'reset')
cla(handles.axes2,'reset')
cla(handles.axes3,'reset')
cla(handles.axes4,'reset')







MATLAB - Load an Image onto Axes

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
%Load Image onto Axes


%Display only required file extensions in folder
[filename pathname] = uigetfile({'*.jpg';'*.png'},'Select Image');

%Concatenate the pathname and filename and store into a single variable
inputImage=strcat(pathname, filename);

%Load Image onto axes1

imshow(inputImage, 'Parent', handles.axes1);

MATLAB - Set text in TextBox on PushButton action

%Example - 1
% --- Executes on button press in pushbutton1
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Set text  in textbox1 on pushbutton1 action


set(handles.textbox1,'string','New Text here on clicking pushbutton1');



%Example - 2
% --- Executes on button press in pushbutton1
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

%Set text  in textbox1 on pushbutton1 action - Convert number to string


intNum=5999; 
% var intNum need to be converted to  a string
strintNum = num2str(intNum);
set(handles.textbox1,'string',strintNum);
 
 
 


Friday, 2 November 2018

MATLAB - Change default background color of the GUI Grid Window


Scroll towards the end of the following function of the code:

function varargout = yourprojectname_OutputFcn(hObject, eventdata, handles)

% Get default command line output from handles structure
varargout{1} = handles.output;

Type the following code here:

%Rashmi:: Set Background Color of the Grid Window
set(gcf,'color','green')










Thursday, 1 November 2018

MATLAB - Start New Project, Save and Change Background Color of GUI Window

1. Type 'guide' in the command window to open up a new or already saved GUI Window:


2.  Choose to open a new Blank GUI Window:



3. Choose File => New to open a new MATLAB GUI Project:



Select Blank GUI and also provide project name under 'Save new figure as:'

4. This will open the GUI Grid Window wherein we can start building the project.

 


5. Now, lets get rid of default Gray color and set it to some other background color. Right Click anywhere on the GUI Grid and choose option 'Editor' to open up the Editor Code Window:



6. Scroll towards the end of the following function:


function varargout = yourprojectname_OutputFcn(hObject, eventdata, handles)

% Get default command line output from handles structure
varargout{1} = handles.output;

7. Type the following code here:

%Rashmi:: Set Background Color of the Grid Window
set(gcf,'color','green')


8. Run the program  using the "Run" option in the menu panel to see the background color change:


MATLAB - Clear all Axes on button press in Pushbutton

% --- Executes on button press in pushbutton function pushbutton_Callback(hObject, eventdata, handles) % hObject    handle to pushbutton (s...