MATLAB: Different computer save folder

computercsvwriteexternalpathnamesavexlswrite

I have a script that I need to share with my professor. I used the commands uigetfile and uigetdir so that my professor can select my sent files for analysing but I was wondering if there was an easier way that my professor could use the scripts and if there is a way that he can write everything to a folder? I have already seen something like this : [pathname ] but I can not figure it out. Please help

Best Answer

Try this out and see if it works. It assumes there an "emg" subfolder. If it can't find it, then it will ask prof to select the dir. Also, "filename" is changed to the full filename. Once the loop is done, it will save all results to a summary.xlsx file in the same dir of mydir (emg directory).
%Figure out key folder paths
ScriptDir = fileparts(mfilename('fullpath')); %script subfolder
MainDir = fileparts(ScriptDir); %folder above the script folder
mydir = fullfile(MainDir, 'emg'); %emg subfolder
%Select the emg folder
if ~exist(EmgDir, 'dir') %If the default emg folder is not there, ask prof to select it
mydir = uigetdir(EmgDir);
end
if isnumeric(mydir)
error('No directory selected');
end
%Get files, not folders
myfiles = dir(fullfile(mydir,'*.*'));
myfiles([myfiles.isdir]) = []; %skip . and .. and all other folders
results = cell(length(myfiles), 1);
for i=1:length(myfiles)
%filename = myfiles(i).name; %this needs the directory too.
filename = fullfile(mydir, myfiles(i).name); %this way, you get the dir + filename
[~, basename, ext] = fileparts(filename);
if isempty(basename)
fprintf('skipping dot file "%s"\n', filename)
continue %go on to next file

end
switch ext
case {'.xls', '.xlsx'}
fprintf('xlsread for file "%s"\n', filename);
emg = xlsread(filename);
case '.csv'
fprintf('it is csvread for file "%s"\n', filename);
emg = csvread(filename);
otherwise
fprintf('Warning: file "%s" is unrecognized extension\n', filename);
continue %go on to next file
end
fprintf('processing data with %d rows and %d columns\n', size(emg,1), size(emg,2));
%%%Plot signal
t = emg(:,1);
y1 = emg (:,2);
N=length(y1);
ls=size(y1);
f = 1/N; %frequency
fs= 1000; %sampling frequency
T = 1/fs; %period between each sample
results{i} = {filename N mat2str(ls) f fs T}; %Saving results (Fixed version)
end
%Saving everything to excel in the same dir of the emg files
targetFile = fullfile(mydir, 'summary.xlsx');
xlswrite(targetfile, cat(1, results{:}));