Fill minimum and maximum values of variables
조회 수: 2 (최근 30일)
이전 댓글 표시
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
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.
답변 (1개)
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)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Spreadsheets에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!