Index exceeds matrix dimensions
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
Réponses (3)
Matt Fig
le 23 Oct 2012
Modifié(e) : Matt Fig
le 23 Oct 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]);
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),:);
0 commentaires
Image Analyst
le 23 Oct 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 commentaire
Richard Brown
le 23 Oct 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
Azzi Abdelmalek
le 23 Oct 2012
Modifié(e) : Azzi Abdelmalek
le 23 Oct 2012
out=Fluorescence (1:40,:)./H(1:40,:)
0 commentaires
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!