Fill minimum and maximum values of variables
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Adam
el 12 de Feb. de 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.
Respuestas (1)
Sarah Crimi
el 12 de Feb. de 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)
0 comentarios
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!