Save original data to a new matrix?
6 views (last 30 days)
Show older comments
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!
0 Comments
Answers (1)
Image Analyst
on 22 Jul 2015
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));
0 Comments
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!