Data analysis and visulatization GUI to calculation mean and std without using built in functions
1 view (last 30 days)
Show older comments
% --- 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.
3 Comments
Answers (1)
Image Analyst
on 23 Dec 2019
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
Image Analyst
on 23 Dec 2019
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).
See Also
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!