Data analysis and visulatization GUI to calculation mean and std without using built in functions

% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
startingFolder = 'C:\Program Files\MATLAB';
if ~exist(startingFolder, 'dir')
% If that folder doesn't exist, just start in the current folder.
startingFolder = pwd;
end
% Get the name of the file that the user wants to use.
defaultFileName = fullfile(startingFolder, '*.xls*');
[baseFileName, folder] = uigetfile(defaultFileName, 'Select a workbook file');
if baseFileName == 0
% User clicked the Cancel button.
return;
end
fullFileName = fullfile(folder, baseFileName);
[numbers, strings, raw] = xlsread(fullFileName)
% Extract column 1 (or whatever).
col1 = numbers(:, 1);
mean(col1);
std(col1);
axes(handles.axes1)
plot(numbers);
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
if(get(hObject,'Value')==get(hObject,'Max'))
mean(numbers)
end
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Hi friends, you can see the outline of the application.I want to do this application but I am so new to matlab, how should I follow a path?
I would be very happy if you help me.

Answers (1)

One way is to attach the data to the handles structure in your pushbutton1_Callback, the Select Data button callback.
handles.col1 = col1;
% Update handles structure
guidata(hObject, handles);
Then, in pushbutton2_Callback (the callback for the calculate button), do the computation on handles.col1.
col1 = handles.col1;
if handles.radiobutton1.Value
output = mean(col1);
operation = 'mean';
else
output = std(col1);
operation = 'std';
end
message = sprintf('The %s of the %d numbers is %f', operation, length(col1), output);
uiwait(helpdlg(message));
An even more professional way would be to put all the workbook filenames into a listbox. Place a listbox on the figure and set the tag to listbox1. Then in the openingFcn, do this
files = dir('*.xls*');
filenames = {files.name};
handles.listbox1.String = filenames;
Then the pushbutton2_Callback() would get the selected filename
selectedItem = handles.listbox1.Value;
allItems = handles.listbox1.String;
selectedFileName = allItems{selectedItem};
fullFileName = fullfile(folder, baseFileName); % Make sure you set folder to whatever it is, for example pwd.
[numbers, strings, raw] = xlsread(fullFileName)
and process it. You could repurpose the pushbutton1_Callback to be a "Specify data folder..." button where you call uigetdir().
See the FAQ for more ways of sharing data between code modules.

4 Comments

thank you so much, and there's one last thing I want to ask, and I want to show the two results on the axes at the same time.How can I?
I don't understand -- what's to be plotted or displayed as an image in an axes? The mean and std are just two numbers. You can use sprintf() to show them in an edit box or static text label if you want, but not an axes control.
Then to see your data on an Excel worksheet, use xlswrite() to send your data to Excel, and then launch it.
xlswrite(workbookFileName, yourData);
winopen(workbookFileName); % Launch Excel with this workbook open (Windows only).

Sign in to comment.

Categories

Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange

Tags

Asked:

on 23 Dec 2019

Commented:

on 16 Jan 2020

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!