Skip to content

Commit

Permalink
allows for multiple sheets to be saved and multiple results tables
Browse files Browse the repository at this point in the history
  • Loading branch information
lacan committed May 19, 2020
1 parent 1c71909 commit 9e75be5
Showing 1 changed file with 56 additions and 31 deletions.
87 changes: 56 additions & 31 deletions functions/EasyXT_GUI.m
Original file line number Diff line number Diff line change
Expand Up @@ -666,52 +666,77 @@ function analyzeImage(varargin)
global analysis_function;

fileDir =[];
data = [];
[dir filename ext] = X.GetCurrentFileName();

[fileDir fileName ext] = X.GetCurrentFileName();

nChan = X.GetSize('C');

%append name of analysis function to the filename
funcData = functions( analysis_function);
funcName = funcData.function;

% Analysis file
if (nargin == 1)
fileDir = varargin{1};

else
fileDir = dir;
end

is_append = (get(findobj('Tag', 'is_append'),'Value'));
if is_append
file = ['/' funcName '-analysis.csv'];
else
file = ['/' filename '.csv'];

end

filePath = [fileDir file];

if exist(filePath, 'file') == 2 && is_append
% Read In the data
data = readtable(filePath, 'Delimiter' ,',');
else
data = table;
end


result = analysis_function(X, @detectAll);
results = analysis_function(X, @detectAll);

result.Image = repmat({filename}, size(result,1),1);

% Append file Name here
data
result
data = [data; result]
writetable(data,filePath, 'Delimiter' ,',');
% Compatibility. If it is just one result, make it into a cell array
if istable( results )
results = {results};
end

nResults = numel( results );
for k = 1:nResults
result = results{k};
sheetName = [];
data = [];
% Append Image name as column
result.Image = repmat({fileName}, size(result,1),1);

resultsName = [funcName '-analysis.xlsx'];

% Try and find this file and see if we need to append or not
if is_append
file = [ '/' resultsName ];
else
file = [ '/' fileName '-' resultsName ];
end
filePath = [fileDir file];

if ~isempty(result.Properties.UserData)
sheetName = result.Properties.UserData;
end

% If it exists, load the existing data
if exist(filePath, 'file') == 2 && is_append
% Read in the data
% Get desired file name from properties
% This does not work if the sheet does not exist, which happens
% the first time the file is created
% Check that it exists first

[name sheetNames] = xlsfinfo(filePath);
if any(ismember(sheetNames, sheetName))
data = readtable(filePath, 'Sheet', sheetName);
else
data = table;
end
else
% This is the first time
data = table;
end

data = [data; result];

if ~isempty(sheetName)
writetable(data,filePath, 'Sheet', sheetName);
else
writetable(data,filePath);
end
end
fprintf('Done for %s\n', fileName)
end

% Helps match surface names
Expand Down

0 comments on commit 9e75be5

Please sign in to comment.