Adding random numbers together

So I'm using this code
% Create a vector of 53 random #s and analyze them.
r = rand([53,1])
% The sum of all the random numbers
sum=sum(([53,1]))
disp(result)
But it doesn't seem to be working.
I'm new to ML
How do I find the sum (and product) of the random numbers?

1 件のコメント

Jan
Jan 2013 年 1 月 31 日
Overwriting the function "sum" by a variable called "sum" also will lead to strange effects.

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

 採用された回答

その他の回答 (3 件)

Sean
Sean 2013 年 1 月 31 日
編集済み: Walter Roberson 2013 年 1 月 31 日

0 投票

% Create a vector of 53 random #s and analyze them.
r = input('enter random number:');
r = rand([53,1])
% The sum of all the random numbers
b = cumsum(53,1)
disp(result)
Sean
Sean 2013 年 1 月 31 日
編集済み: Walter Roberson 2013 年 1 月 31 日

0 投票

% Author: Sean Walsh
% Create a vector of 53 random #s and analyze them.
r = rand([53,1]);
% The sum of all the random numbers
sum(r)
% The product of all the random numbers
prod(r)
This is what I wrote.
This is what came out.
>> lab0202
ans =
27.0784
ans =
2.1169e-21
>> clear
>> lab0202
K>> clear
>> lab0202
ans =
27.7177
ans =
6.1916e-21
It didn't list all 53?
Sean
Sean 2013 年 1 月 31 日

0 投票

I got it..thank you<3

カテゴリ

ヘルプ センター および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by