Hey guys, basically I need to produce a script that will ask for a set of values. The values then need to be added up in backwards order and put onto a graph. So for example, if the user entered [2, 3, 5, 7]. I would need my y values to be (7, 7+5, 7+5+3, 7+5+3+2). I hope this makes sense.
I've started with:
'x = input('Enter values for distance of each load from A:');
z = input('Enter values for each load:');
plot(x,y);'
I'm just struggling to think of a command I can use to produce my y values as said before. Any help would be great, once I get this sorted I can really start moving forwards with this!

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 11월 6일

0 개 추천

A=[2, 3, 5, 7]
cumsum(fliplr(A))

댓글 수: 3

mikev438
mikev438 2013년 11월 6일
Wow, that was exactly what I asked for! I've realised I made a slight mistake though I apologise! How would I make it so from the original example it would be (7+5+3+2, 7+5+3, 7+5, 7). Again, I'm really sorry for that mistake, but I greatly appreciate the help!
A=[2, 3, 5, 7]
out=fliplr(cumsum(fliplr(A)))
mikev438
mikev438 2013년 11월 6일
That's brilliant, thank you so much!

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

추가 답변 (0개)

카테고리

태그

질문:

2013년 11월 6일

댓글:

2013년 11월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by