sum over matrix columns
2 views (last 30 days)
Show older comments
Hi all, I have the following problem:
I defined the matrix A: A=[1 2 1; 4 5 1] then with sum(A) I got the desired sums calculated: 5, 7, 2. So far so fine. After that I executed the following command: sum((bsxfun(@minus,x,permute(X,[1,3,2]))/h).^2), where x=[1 2 3 6 7; 4 5 2 1 6] and X=[1 2 1; 4 5 3], h=0.1 and got the following error message: "Subscript indices must either be real positive integers or logicals." This error occures now everytime I want to execute A=[1 2 3; 4 5 6; 1 0 1] and sum(A). What did I wrong?
Do you maybe know what might be a reason for such behaviour? Thnak you Best Regards Xanka
1 Comment
David Young
on 10 Aug 2015
Difficult to know - I don't get the error with your code:
x=[1 2 3 6 7; 4 5 2 1 6];
X=[1 2 1; 4 5 3];
h = 0.1;
sum((bsxfun(@minus,x,permute(X,[1,3,2]))/h).^2)
ans(:,:,1) =
0 200 800 3400 4000
ans(:,:,2) =
200 0 1000 3200 2600
ans(:,:,3) =
100 500 500 2900 4500
How are you executing your code? Is it in an m-file or are you pasting it into the command window? Are you sure that you are only executing the correct lines of code?
For trying ideas out, I recommend using cell mode in the editor.
Accepted Answer
More Answers (1)
Azzi Abdelmalek
on 10 Aug 2015
Check if permute was not used as a variable in your code. Type
permute
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!