Index exceeds matrix dimensions

3 Ansichten (letzte 30 Tage)
Ryan
Ryan am 22 Okt. 2012
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 Kommentar
Ryan
Ryan am 30 Okt. 2012
fixed this by clearing J at the end of each iteration of i.
K = cat(1,K,J);
J = [];
end

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Matt Fig
Matt Fig am 23 Okt. 2012
Bearbeitet: Matt Fig am 23 Okt. 2012
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 am 23 Okt. 2012
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 Kommentar
Richard Brown
Richard Brown am 23 Okt. 2012
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

Melden Sie sich an, um zu kommentieren.


Azzi Abdelmalek
Azzi Abdelmalek am 23 Okt. 2012
Bearbeitet: Azzi Abdelmalek am 23 Okt. 2012
out=Fluorescence (1:40,:)./H(1:40,:)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by