How to use a for loop for concatenated matrices. [counts, centers] = hist(X);
Show older comments
Hello Friends,
I am trying to do the following:
[counts1, centers1] = hist(X); [counts2, centers2] = hist(Y);
%X and Y both are the n x 1 matrices, i.e., have only one column with real numbers.
counters = [counts1, centers1; counts2, centers2]; %Here, I am trying to make a 2x2 matrix.
Now, I want to compute the expected value as follows:
[row, col] = size(counters);
E = zeros(row);
for i = 1:row
E(i) = (counters(i,1)*counters(i,2)')/sum(counters(i,1));
fprintf('%f\n', E(i)); % Trying to print it on command window.
end
I am not getting expected results. Expected Values E(1) and E(2) should print on command window separately for each sets of counts & centers (let's say we want to print them in column). Please advise. Thanks in advance.
2 Comments
Stephen23
on 15 Feb 2015
"I am not getting expected results": so exactly what does this code do now? It would be better if you described exactly the desired output, then we could tell you how to achieve this. Give examples, and please format them as code!
hello_world
on 15 Feb 2015
Edited: hello_world
on 15 Feb 2015
Accepted Answer
More Answers (0)
Categories
Find more on Data Distribution Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!