Hi everyone! I need help!
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I need to get the probability of every element in a 3D matrix (Mat) which is 83x92x80
% code
%
[r, c, t] = size(Mat);
y = zeros(r,c,t);
p = zeros(r,c,t);
for i = 1:c;
for j = 1:r;
for k=1:t;
y(j,i,k) = sum(Mat (:,:,[k]) == Mat(j,i,k));
p(j,i,k) = y(j,i,k)/80;
end
end
end
First, I am getting an error “Assignment has more non-singleton rhs dimensions than non-singleton subscripts”. Second, I am not quite sure if this is how I should do what I want to do. I really appreciate your help.
Many thanks
Endaw
3 comentarios
Bob Thompson
el 9 de Abr. de 2018
The error occurs because your code is trying to fit a three dimensional array, created by the sum() command, into a single element. If you're looking for the total summation, James suggested a decent solution.
Respuestas (2)
James Tursa
el 9 de Abr. de 2018
Maybe adding another sum gets the result you want?
y(j,i,k) = sum(sum(Mat (:,:,[k]) == Mat(j,i,k)));
3 comentarios
James Tursa
el 10 de Abr. de 2018
OK, at this point I think we need an example to understand what it is you want. Can you show us a sample small sized array, say 2x3x4, and show us this array and also show us the exact desired output for this array?
Steven Lord
el 10 de Abr. de 2018
Are you trying to compute the histogram of the elements in that array? If so take a look at the histogram function (or the histcounts function if you just need the counts without the picture.)
1 comentario
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!