Fill minimum and maximum values of variables

1 回表示 (過去 30 日間)
pradnya mhetre
pradnya mhetre 2019 年 2 月 12 日
回答済み: Sarah Crimi 2019 年 2 月 12 日
Hi,
I have excel files containing list of variable and .m file having minimum and maximum values of those variables.I want to fill random values within range(i. e. min and max) from .m file of respective variables in excel.
eg.I have two variables a and b(of any datatype).Ranges for these variables given in .m isa= [-10 10] and b=[0 20].
Now I want to fill random values within range specified in .m to excel.
Thanks.
  2 件のコメント
Adam
Adam 2019 年 2 月 12 日
You need to define a distribution for your random values. If you just use rand and scale to the relevant range you will basically just have a white distribution, whereas if you use a normal distribution then the values will obviously congregate more around the mean with few at the edges of the range.
It's confusing what your question is really though. You have various components to what you are trying to do - read from Excel, do some maths in Matlab, write to Excel. It isn't clear which you are asking about.
pradnya mhetre
pradnya mhetre 2019 年 2 月 12 日
Thanks for your reply.
Basicaly I have an excel file having vaibles list(column wise) and .m file having minimum and maximum values of same variables.
I want to generate random test cases containing min and max values of all varibles.
eg.
a b
Testcase1 -10 5
Testcase2 --5 9
Testcase3 8 14
Likewise these values should be filled in excel file by reading .m file.

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

回答 (1 件)

Sarah Crimi
Sarah Crimi 2019 年 2 月 12 日
I think that this may be what you are looking for:
%Number of test subjects
N1 = 10;
%Set A1 =-10 and B1=10 for first variable.
a1=-10;
b1=10;
%Set A2 = 0 and B2=20 for the second variable.
a2=0;
b2=20;
%Preallocate cells.
testcase = cell(N1,1)
r1 = cell(N1,1)
r2 = cell(N1,1)
for i=1:N1
r1{i,1} = randi([a1 b2], 1, 1)'
r2{i,1} = randi([a2 b2], 1, 1)'
%For loop to get the variables.
testcase{i,1} = strcat(['testsubject' num2str(i)])
end
l = [testcase r1 r2]
xlswrite('data1.xls',l)

カテゴリ

Help Center および File ExchangeSpreadsheets についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by