Subtraction Operation Within Cell Array
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Jan
2017-8-23
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});
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!