sum over matrix columns

조회 수: 2 (최근 30일)
xanka bocem
xanka bocem 2015년 8월 10일
답변: xanka bocem 2015년 8월 10일
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
David Young
David Young 2015년 8월 10일
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.

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

채택된 답변

xanka bocem
xanka bocem 2015년 8월 10일
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

추가 답변 (1개)

Azzi Abdelmalek
Azzi Abdelmalek 2015년 8월 10일
Check if permute was not used as a variable in your code. Type
permute

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by