Export logical uitable array to be used in separate GUI

1 visualizzazione (ultimi 30 giorni)
I want to save data from one GUI logical uitable that sets the filename as the name entered in the Full Name edit box. Then later access all of the data at once with another GUI in order to compare the data and group sets of data together. Currently I have
function Submit_pushbutton_Callback(hObject, eventdata, handles)
BlazerID = get(handles.BlazerID_edit, 'string'); %get blazer id that was entered
Fullname = get(handles.FullName_edit, 'string'); %get full name
filename = strcat(BlazerID,Fullname); %combine Blazer ID and Fullname
hour = get(handles.hours_uitable, 'data'); %get data from uitable
save(filename, 'hour'); %save uitable data as .mat file with filename = Blazer ID and Fullname that was entered
The other GUI will import all .mat files from the current directory and compare the uitable logical data in order to combine groups of people together according to their available schedules. Currently I have
MyDirInfo = dir('*.mat');%load .mat files from current directory
but this doesn't seem to allow me direct access to the original uitable logical array

Risposta accettata

Corey Williams
Corey Williams il 24 Apr 2016
Modificato: Corey Williams il 24 Apr 2016
I finally figured it out after banging my head against the wall forever, I'm not very fluent with matlab considering my orignal professor was fired because of lack of teaching and we've been rushed through the remainder of the semester. Here's my code to create a .mat file in the Submit_pushbutton_Callback of the first GUI
% --- Executes on button press in Submit_pushbutton.
function Submit_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to Submit_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
BlazerID = get(handles.BlazerID_edit, 'string'); %get blazer id that user entered
hour = get(handles.hours_uitable, 'data'); %get data from uitable
save(['C:\Users\jjtar\Desktop\GUI\Mat_File_Directory\' BlazerID '.mat'], 'hour', 'BlazerID'); %save file name = Blazer ID that was entered and save Data and BlazerID as variables
and here is my code in the opening function of the second GUI to get data from all of the .mat files that were created in the first GUI
for MyDirInfo = GetFileNames('C:\Users\jjtar\Desktop\GUI\Mat_File_Directory\');
for index = 1:numel(MyDirInfo) %Loop through for the number of files
GetFileName = MyDirInfo{index}; %Get string out of cell that includes name
MyDirName = strcat('C:\Users\jjtar\Desktop\GUI\Mat_File_Directory\',GetFileName); %Combine Directory location and file name
Data = matfile(MyDirName); %Get file Data
FileData=Data.hour; %Get .hour variable
end;
end;
Hopefully I help someone out that may be as lost as I am at using matlab
  2 Commenti
Corey Williams
Corey Williams il 24 Apr 2016
And this is the GetFileNames function that has to be saved in the same directory as the GUI is in, thanks to my current professor for providing this to me
function [ FileNames ] = GetFileNames ( DirectoryPath )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
Files = GetFiles(DirectoryPath);
FileNames = [];
if (isempty(Files))
% do nothing
else
for x=1:length(Files)
FileNames{x,1} = Files(x).name;
end
end;
end
Walter Roberson
Walter Roberson il 25 Apr 2016
Please use fullfile() instead of string concatenation on the file names and directories.

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 17 Apr 2016
Your variable names hint that BlazerName is a directory, since "FullName" tends to hint at complete name. But you are not treating BlazerName as a directory: you are using strcat to combine it with FullName instead of using fullfile() . If it is intended to be a directory then you are missing out on the path separator between directory and file name.
  1 Commento
Corey Williams
Corey Williams il 18 Apr 2016
I should have clarified on that code some more, or left that part out... I combined the BlazerID and Fullname to create the name of the File in order to make the new created file more unique for my other GUI which will create a schedule of groups and include multiple users BlazerID and Full Name. So, the files that are created will resemble this 'BlazerIDFull Name.mat' or, to be more clear, 'clw6330Corey Williams.mat'

Accedi per commentare.

Categorie

Scopri di più su App Building in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by