column wise adding

i had y= 1 6 4 7 5 3 6 4 9 n so on... i want yout=1+6+4 7+5+3 6+4+9

답변 (1개)

Andrei Bobrov
Andrei Bobrov 2011년 6월 8일

0 개 추천

doc reshape
doc sum
yout = sum(reshape(y,3,[]));
EDIT
z = sum((x-y).^2,2);

댓글 수: 2

mahaveer hanuman
mahaveer hanuman 2011년 6월 8일
i mean i have:
y(0)= 1 2 5
y(1)= 3 5 7
y(2)= 2 6 4
x(0)= 1 -2 7
x(1)= 3 5 4
x(2)= 2 -6 2
now i need output as:
z(0)=(1-1)^2+(2+2)^2+(5-7)^2
z(0)=20
and so on for z(1),z(2).
please help!!
David Young
David Young 2011년 6월 8일
y(0) = 1 2 5 does not make sense. First because MATLAB array indexes start from 1; second because if y is a numerical array each element must contain a single value, not 3 values. Please can you clarify what you want to do?

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

카테고리

도움말 센터File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기

질문:

2011년 6월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by