Export logical uitable array to be used in separate GUI

2 ビュー (過去 30 日間)
Corey Williams
Corey Williams 2016 年 4 月 17 日
コメント済み: Walter Roberson 2016 年 4 月 25 日
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

採用された回答

Corey Williams
Corey Williams 2016 年 4 月 24 日
編集済み: Corey Williams 2016 年 4 月 24 日
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 件のコメント
Corey Williams
Corey Williams 2016 年 4 月 24 日
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 2016 年 4 月 25 日
Please use fullfile() instead of string concatenation on the file names and directories.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 4 月 17 日
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 件のコメント
Corey Williams
Corey Williams 2016 年 4 月 18 日
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'

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by