Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
176 views

Matlab Calculator GUI (Assignment)

The document describes two problems involving Matlab GUI programming. The first problem involves creating a calculator GUI that performs basic mathematical operations. The second problem involves creating a GUI for string processing that can change the case of strings, concatenate strings, extract portions of strings, and extract characters from strings. For both problems, the student is asked to write the main program and user-defined functions, and explain the functions used.

Uploaded by

aman singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views

Matlab Calculator GUI (Assignment)

The document describes two problems involving Matlab GUI programming. The first problem involves creating a calculator GUI that performs basic mathematical operations. The second problem involves creating a GUI for string processing that can change the case of strings, concatenate strings, extract portions of strings, and extract characters from strings. For both problems, the student is asked to write the main program and user-defined functions, and explain the functions used.

Uploaded by

aman singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

Assignment

Matlab Programming
BCA-V

Problem 1

Make a GUI based Calculator using Matlab. The calculator should perform the basic operations.

Make a final report which should consist of the main program.


Give details of all the in-built functions used in making calculator.
Explain the working of user-defined functions used in it.

function varargout = calculator(varargin)

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @calculator_OpeningFcn, ...


'gui_OutputFcn', @calculator_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

function calculator_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

function varargout = calculator_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function pushbutton7_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('7');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton8_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('8');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton9_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');
new=('9');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton4_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('4');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton5_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('5');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton6_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('6');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton1_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('1');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton2_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('2');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbutton3_Callback(hObject, eventdata, handles)


old=get(handles.text3,'string');

new=('3');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbuttonmul_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('*');

new1=strcat(old,new);

set(handles.text3,'string',new1)

function pushbuttonminus_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('-');

new1=strcat(old,new);

set(handles.text3,'string',new1)

function pushbuttonplus_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('+');

new1=strcat(old,new);

set(handles.text3,'string',new1)

function pushbuttonequal_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=eval(old); % calculate value expression passed in a string

set(handles.text2,'string',new);

set(handles.text3,'string', '');

function pushbuttondot_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('.');

new1=strcat(old,new);

set(handles.text3,'string',new1);
function pushbutton0_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('0');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function pushbuttondel_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new= char();

for i= 1: (length (old))-1

new(i)=old(i);

end

set(handles.text3,'string',new);

function pushbuttondiv_Callback(hObject, eventdata, handles)

old=get(handles.text3,'string');

new=('/');

new1=strcat(old,new);

set(handles.text3,'string',new1);

function edit1_Callback(hObject, eventdata, handles)

function edit1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function text2_Callback(hObject, eventdata, handles)

function text2_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function text3_Callback(hObject, eventdata, handles)


function text3_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function pushbuttonclear_Callback(hObject, eventdata, handles)

old=get(handles.text2,'string');

new= char();

for i= 1: (length (old))-1

new(i)=old(i);

end

set(handles.text2,'string',new);

Problem 2

Create a GUI interface using Matlab for “String Processing”. The interface should do the following
functions-

a) Change case of string (Lower, Upper, Sentence, Title)


b) Concatenate string
c) Extracting a portion of a String
d) Extracting a character from a String

Make a final report which should consist of the main program.


Give details of all the in-built functions used in making calculator.
Explain the working of user-defined functions used in it.
function varargout = stringconvert(varargin)

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename, ...

'gui_Singleton', gui_Singleton, ...

'gui_OpeningFcn', @stringconvert_OpeningFcn, ...

'gui_OutputFcn', @stringconvert_OutputFcn, ...

'gui_LayoutFcn', [] , ...

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_State.gui_Callback = str2func(varargin{1});

end

if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

function stringconvert_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;

guidata(hObject, handles);

function varargout = stringconvert_OutputFcn(hObject, eventdata, handles)

varargout{1} = handles.output;

function pushbuttonchngUcase_Callback(hObject, eventdata, handles)

old=get(handles.text1,'string');

newStr = upper(old)

set(handles.textout,'string',newStr);

function pushbuttonconcatenate_Callback(hObject, eventdata, handles)

old=get(handles.text1,'string');

new=get(handles.text2,'string');

str3 = [old new];

set(handles.textout,'string',str3);

function pushbuttonexport_Callback(hObject, eventdata, handles)

old=get(handles.text1,'string');

t = table(old)

for row = 1 : size(t, 1)

oldString = t.myStrings{row};

t.old{row} = oldString(1:end-1);

end

set(handles.textout,'string',t);

function pushbuttonexchar_Callback(hObject, eventdata, handles)

old=get(handles.text1,'string');

new = old(double(old) > 64)


set(handles.textout,'string',new);

function text1_Callback(hObject, eventdata, handles)

function text1_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function text2_Callback(hObject, eventdata, handles)

function text2_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function textout_Callback(hObject, eventdata, handles)

function textout_CreateFcn(hObject, eventdata, handles)

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

function pushbuttonchngelcase_Callback(hObject, eventdata, handles)

old=get(handles.text1,'string');

newStr = lower(old)

set(handles.textout,'string',newStr);

You might also like