if loop not executing
이전 댓글 표시
i have dataset of 80 numbers=[1:1:80]
now i want to take first 8 values ,multiply each value by 2 and divide each by 2,so i will have 8 values each for multiplication and division,and then want to find average for that multilaction values and division values,same way i want to perform for those 80 values from 1st 8,2nd 8,3rd 8........10th8 please help..
i tried the folowing but it is not executing
z=0
if index<=8 +z
Sum=index+2
mul=index.*2
end
avg=mean(Sum)
avg=mean(mul)
z=z+1
i get answer as z=0
z=1
please help
댓글 수: 4
Fangjun Jiang
2011년 12월 28일
Where is the for-loop and what is your variable index?
kash
2011년 12월 28일
Walter Roberson
2011년 12월 28일
There is no such thing as an "if loop". There is "for loop" and "while loop" and "if statement", but not "if loop".
kash
2011년 12월 29일
채택된 답변
추가 답변 (2개)
Image Analyst
2011년 12월 28일
1 개 추천
I answered this where you first asked it http://www.mathworks.com/matlabcentral/answers/24562-selecting-an-image-from-folder My answer of using conv was also suggested by someone else in your third thread for this http://www.mathworks.com/matlabcentral/answers/24848-performing-certain-operation-from-a-set-a-certain-set-of-values
Can you explain in words what you actually want to do? Is it a running average? Or something else?
댓글 수: 2
kash
2011년 12월 28일
Image Analyst
2011년 12월 29일
For example, output(1) = mean(input(1):input(8)), output(2) = mean(input(2):input(9)) and so on, moving over one element at a time.
Fangjun Jiang
2011년 12월 28일
0 개 추천
if-else statement won't do any loop.
I assume this is an exercise. You almost need to re-work on the code completely.
"multiply each value by 2 and divide each by 2", but you are adding it by 2.
It's meaningless to do mean() on a scalar.
I suggest you go to the MATLAB document, MATLAB->Getting Started.
카테고리
도움말 센터 및 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!