Obtain a specif value in a vector

Hi guys, I'm having a problem; let's say I have a code like the following:
clear
g = ones(1,1);
serv = (randi([0, 10], [10,10])).*g;
meanserv = mean(serv);
At this point, what I need is a value of g such that meanserv(1,1) is equal to 0.3 and meanserv(1,10) is equal to 0.7; I was thinking to use an fsolve or a simple while/if but I can't figure out how to obtain those results.
Thanks in advance.

4 件のコメント

Adam
Adam 2019 年 10 月 22 日
If you have the Statistics toolbox
doc normrnd
will give you normally distributed numbers from a population with a given mean, but a sample of 10 from this will give you a mean that is often a notable distance away from 0.3. The only way you could guarantee exactly 0.3 is to fix the numbers instead of taking random numbers. You could do a loop to get as close as possible to 0.3 if that is acceptable. Though as an aside I think I am correct in saying 0.3 cannot be exactly represented by a double anyway.
Giuseppe Pintori
Giuseppe Pintori 2019 年 10 月 22 日
I was using something like this
while (meanserv(1,1) > 0.3) && (meanserv(1,10) < 0.7)
if meanserv(1,1) < 0.3
break
end
if meanserv(1,10) > 0.7
break
end
end
Adam
Adam 2019 年 10 月 22 日
Nothing changes in that while loop though!
Giuseppe Pintori
Giuseppe Pintori 2019 年 10 月 22 日
Exactly

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

回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeProgramming についてさらに検索

製品

リリース

R2019b

質問済み:

2019 年 10 月 22 日

コメント済み:

2019 年 10 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by