Save original data to a new matrix?

Hello! I have the following code:
[vars]= find(difference < center - marginOfError | difference > center + marginOfError);
cd('Threshold Tested Data');
saving = strcat(fractions(nn).name(1:end-4),'_and_Threshed.mat');
save(saving);
The current code runs fine. However,when the new matrix saves, it's just a series of ones. I would like it to save the exact cells from my variable 'difference' that exceed the margin set by 'center +/- marginOfError'.
Thanks!

Answers (1)

Try this:
% Find out what elements of "differences" we want to keep:
elementsToKeep = abs(difference - center) > marginOfError;
% Create a filename:
baseFileName = sprintf('%s_and_Threshed.mat', fractions(nn).name(1:end-4));
% Create a subfolder.
folder = fullfile(pwd, 'fractions(nn).name(1:end-4)');
if ~exist(folder, 'dir')
% Does not exist yet - need to create it.
mkdir(folder);
end
% Combine folder and baseFileName into one string.
fullFileName = fullfile(folder, baseFileName);
% cd('Threshold Tested Data'); % don't use cd!!!
% Save only the elements of "differences" that we want to keep into our mat file.
save(fullFileName, differences(elementsToKeep));

Products

Asked:

on 22 Jul 2015

Answered:

on 22 Jul 2015

Community Treasure Hunt

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

Start Hunting!