Fill minimum and maximum values of variables

2 visualizzazioni (ultimi 30 giorni)
pradnya mhetre
pradnya mhetre il 12 Feb 2019
Risposto: Sarah Crimi il 12 Feb 2019
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 Commenti
Adam
Adam il 12 Feb 2019
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 il 12 Feb 2019
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.

Accedi per commentare.

Risposte (1)

Sarah Crimi
Sarah Crimi il 12 Feb 2019
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)

Community Treasure Hunt

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

Start Hunting!

Translated by