hi, im trying to produce the answer for this equation in vector. example for a[1 2 3 4 5], im expecting my answer to be y[0 4 8 10 12.5]. can anyone help me to explain about this?thanks
조회 수: 1 (최근 30일)
이전 댓글 표시
a=[1 2 3 4 5];
for n=1:5
y=[(a(1,n)^2)/2];
end
[y]
댓글 수: 0
채택된 답변
Junaid
2011년 12월 4일
I don't your formula to produce y. But to get equal length vector to a, you should do like this.
a=[1 2 3 4 5];
y=size(a);
for n=1:5
y(n)=[(a(1,n)^2)/2];
end
You have store each value of Y, but in your code you replace previous value by new value. I hope now you can debug yourself for your desired answer.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!