Index exceeds matrix dimensions
이전 댓글 표시
I've got two matrices, Fluorescence <3840x15> and H <96x15>. I want to divide 40 Fluorescence values in each column by a value in the corresponding H column. Running the code as is results in a matrix J, but with just the first 40 rows of Fluorescence divided by the first row of H, instead of the <3840x15> matrix I wanted to end up with.
J = [];
K = [];
k = 1;
n = 1;
for i = 1:(r/40)
for j = 1:c
I = Fluorescence(k:(k+39),j) / H(n,j);
J = cat(2,J,I);
end
k = k + 40;
n = n + 1;
K = cat(1,K,J);
end
답변 (3개)
I think you mean this:
F = randi(100,3840,15); % Random 3840-by-15
H = randi(100,96,15); % Random 96-by-15;
J = F./expand(H,[40,1]);
Another way to do it without using the EXPAND function (with the same F and H as above):
J = zeros(3840,1);
J(1:40:end) = 1;
J = F./H(cumsum(J),:);
Image Analyst
2012년 10월 23일
Do you have the Image Processing Toolbox? If you do, it's just two lines:
% Generate sample data.
Fluorescence = rand(3840, 15);
H = rand(96,15);
% Resize H to be the same size as Fluorescence.
H_matchingSize = imresize(H, size(Fluorescence), 'nearest');
% Divide them.
output = Fluorescence ./ H_matchingSize;
Or even one line:
output = Fluorescence ./ imresize(H, size(Fluorescence), 'nearest');
댓글 수: 1
Richard Brown
2012년 10월 23일
or with a little more convoluted syntax, you can do it without the image processing toolbox
H_matching_size = interp1(1:96, H, reshape(repmat(1:96, 40, 1), 96*40, 1));
which is basically what imresize is doing
Azzi Abdelmalek
2012년 10월 23일
편집: Azzi Abdelmalek
2012년 10월 23일
out=Fluorescence (1:40,:)./H(1:40,:)
카테고리
도움말 센터 및 File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!