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
Fangjun Jiang 2011 年 12 月 28 日
Where is the for-loop and what is your variable index?
kash
kash 2011 年 12 月 28 日
Sorry fangjun it is "if loop"
index is my dataset=[1:1:80]
Walter Roberson
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
kash 2011 年 12 月 29 日
ok walter it is "if statement"

サインインしてコメントする。

 採用された回答

bym
bym 2011 年 12 月 28 日

0 投票

use reshape to organize your values into 8 rows and 10 columns. You can then use mean() after your multiplications & divisions.
x = 1:80;
x = reshape(x,8,[]);
...

その他の回答 (2 件)

Image Analyst
Image Analyst 2011 年 12 月 28 日

1 投票

Can you explain in words what you actually want to do? Is it a running average? Or something else?

2 件のコメント

kash
kash 2011 年 12 月 28 日
Actually i need in final of 10 average values in sum and multiplication,and i need each
foe example
the sum of first 8 values must be stored in an variable and so on till end(last 8 values)and same for multiplication,and average also
i dont know what u mean by running average
Image Analyst
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
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 ExchangeLoops and Conditional Statements についてさらに検索

質問済み:

2011 年 12 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by