sum over matrix columns

6 Ansichten (letzte 30 Tage)
xanka bocem
xanka bocem am 10 Aug. 2015
Beantwortet: xanka bocem am 10 Aug. 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 Kommentar
David Young
David Young am 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.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

xanka bocem
xanka bocem am 10 Aug. 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

Weitere Antworten (1)

Azzi Abdelmalek
Azzi Abdelmalek am 10 Aug. 2015
Check if permute was not used as a variable in your code. Type
permute

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by