Subtraction Operation Within Cell Array
조회 수: 11 (최근 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일
If only the 3 last lines concern the problem, the rest of the code is confusing only.
채택된 답변
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에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!