Fill minimum and maximum values of variables

조회 수: 2 (최근 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 CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by