sum over matrix columns

2 vues (au cours des 30 derniers jours)
xanka bocem
xanka bocem le 10 Août 2015
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 commentaire
David Young
David Young le 10 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

xanka bocem
xanka bocem le 10 Août 2015
Thank you all.
I found the mistake. I used sum as variable and that´s why I got then the error when I tried to use sum as a function. Best Regards Xanka

Plus de réponses (1)

Azzi Abdelmalek
Azzi Abdelmalek le 10 Août 2015
Check if permute was not used as a variable in your code. Type
permute

Catégories

En savoir plus sur Programming 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!

Translated by