Subtraction Operation Within Cell Array

6 views (last 30 days)
itend
itend on 23 Aug 2017
Commented: itend on 24 Aug 2017
Hello,
I have a 2 x 6 cell array, each cell in row #1 {1 -> 6, 2} contains a 1024 x 1024 x 100 matrix. The first cell in row #2 {2,1} contains a 1024 x 1024 matrix. I want to subtract the cell in {2,1} from each "slice" of each matrix in row#1. I am having trouble putting together code that would do this... here is what I have so far (the bit that this question is referring to is the last 3 lines of code):
%%Get a list of all files in the folder with the desired file name pattern.
filePattern = fullfile(myFolder, '*.spe');
dinfo = dir(filePattern);
filenames = fullfile(myFolder, {dinfo.name});
output = cellfun(@readSPE, filenames, 'uniform', 0); %convert to spe
output = cellfun(@double,output, 'uniform', 0); %convert to double
%%remove first five frames to reduce variability
output = cellfun(@(x)x(:,:,5:end),output,'uni',false);
%%import background
bkg = median(double(readSPE('bkg_10AOC_LightsOff.spe')),3); %temporal median + double
output{2,1} = bkg; %insert into cell array
%%subtract bkg from each cell
for i = 1:length(filenames)
output{1,i} - output{2,1};
end
I am not sure that this is accomplishing what I... any suggestions? If anyone has suggestions on a better methodology please let me know :)
Thank you for your time and help!!
  2 Comments
Jan
Jan on 23 Aug 2017
If only the 3 last lines concern the problem, the rest of the code is confusing only.

Sign in to comment.

Accepted Answer

Jan
Jan on 23 Aug 2017
Your idea looks fine:
for i = 1:length(filenames)
output{1, i} = output{1,i} - output{2,1};
end
This works since R2016b. For older versions:
output{1, i} = bsxfun(@minus, output{1,i}, output{2,1});

More Answers (0)

Community Treasure Hunt

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

Start Hunting!