필터 지우기
필터 지우기

Hi everyone! I need help!

조회 수: 1 (최근 30일)
Engdaw Chane
Engdaw Chane 2018년 4월 9일
댓글: Engdaw Chane 2018년 4월 11일
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
Engdaw Chane
Engdaw Chane 2018년 4월 9일
Thank you Bob! The error occurring in the for loop. and the error is: "Assignment has more non-singleton rhs dimensions than non-singleton subscripts." I would happy to know another way of calculating the probability of each element in the third dimension.
Kindly, Engdaw
Bob Thompson
Bob Thompson 2018년 4월 9일
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.

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

답변 (2개)

James Tursa
James Tursa 2018년 4월 9일
Maybe adding another sum gets the result you want?
y(j,i,k) = sum(sum(Mat (:,:,[k]) == Mat(j,i,k)));
  댓글 수: 3
James Tursa
James Tursa 2018년 4월 10일
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?
Engdaw Chane
Engdaw Chane 2018년 4월 11일
My matrix has 83 rows, 92 columns and 80 months. What I need is the probability of each value along time (80 months). For example, this is how I calculated the probability of zero values for every row and column along time.
% code
sum(matrix == 0, 3) ./ (size(matrix,3)); % here the result was just a matrix (83x92).
%
Now, I have to calculate the probability of all values.
For example if a value (at a specific row and column) occurred once in all 80 files, the probability for that value would be 1/80=0.0125. But this probability value changes if that specific value occurred multiple times in the 80 files.
thank you for your effort to save me!
Kindly, Chane

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


Steven Lord
Steven Lord 2018년 4월 10일
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
Engdaw Chane
Engdaw Chane 2018년 4월 11일
Steven Lord
This is what I need to do; My matrix has 83 rows, 92 columns and 80 months. What I need is the probability of each value along time (80 months). For example, this is how I calculated the probability of zero values for every row and column along time.
% code
sum(matrix == 0, 3) ./ (size(matrix,3)); % here the result was just a matrix (83x92).
%
Now, I have to calculate the probability of all values.
For example if a value (at a specific row and column) occurred once in all 80 files, the probability for that value would be 1/80=0.0125. But this probability value changes if that specific value occurred multiple times in the 80 files.
thank you for your effort to save me!
Kindly, Chane

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

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by