Save original data to a new matrix?

6 Ansichten (letzte 30 Tage)
Hannah Schultejans
Hannah Schultejans am 22 Jul. 2015
Beantwortet: Image Analyst am 22 Jul. 2015
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!

Antworten (1)

Image Analyst
Image Analyst am 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));

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by