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

댓글 수: 1

fixed this by clearing J at the end of each iteration of i.
K = cat(1,K,J);
J = [];
end

댓글을 달려면 로그인하십시오.

답변 (3개)

Matt Fig
Matt Fig 2012년 10월 23일
편집: Matt Fig 2012년 10월 23일

1 개 추천

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]);
Note that the EXPAND function is found on this page: EXPAND
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
Image Analyst 2012년 10월 23일

0 개 추천

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

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
Azzi Abdelmalek 2012년 10월 23일
편집: Azzi Abdelmalek 2012년 10월 23일

0 개 추천

out=Fluorescence (1:40,:)./H(1:40,:)

카테고리

도움말 센터File Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

질문:

2012년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by