User Tools


User contributed code and examples

This section contains tools, scripts and examples contributed by jEPlus users. If you have already registered on the jeplus.org website, you can create your own article by using the forms at the bottom of this page.


Matlab code example for writing Sobol sample to joblist.txt

By Navid Delgarm

Notes:

  1. This MATLAB script file will be run in MATLAB version 2014 and above. No using 2013, 2012… please.
  2. The generated joblist.txt file will be saved in Matlab's current working directory. To change the location, please edit line 47.


%%% General code for producing joblist.txt in MATLAB environment%%
% By: Navid Delgarm%
clc;
clear ;
close all;
format short
tic       % to Know the run time

%%% UpperBand and lowerBand of each parameter%%%%
%%%This MATLAB script file includes 6 arbitrary parameters%%%
LB1=0;  UB1=359;
LB2=2;  UB2=6;
LB3=0;  UB3=1;
LB4=10; UB4=50;
LB5=0;  UB5=180;
LB6=0;  UB6=0.5;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

N=2000;           % number of sample points
nVar=6;           % number of decision variables

%%%Implementation of different sampling methods. You can program any arbitrary sampling method in this part%%%%%
%%% Here is Sobol sequences method in MATLAB %%%
p = sobolset(nVar,'Skip',1e3,'Leap',1e2);
p = scramble(p,'MatousekAffineOwen');
A=net(p,N);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% The generated numbers are transferred to their correct range of parameters and rounded to two decimal places %%%
x1=round((LB1+(UB1-LB1).*A(:,1))*100)/100;
x2=round((LB2+(UB2-LB2).*A(:,2))*100)/100;
x3=round((LB3+(UB3-LB3).*A(:,3))*100)/100;
x4=round((LB4+(UB4-LB4).*A(:,4))*100)/100;
x5=round((LB5+(UB5-LB5).*A(:,5))*100)/100;
x6=round((LB6+(UB6-LB6).*A(:,6))*100)/100;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%% Here the joblist.txt is created automatically%%%
y1=(1:N)';                           % job IDs: 1,2,3,4,...,N
y2=zeros(N,2);                       % Two zero columns for Weather file and IDF file index (0,0)
T = table(y1,y2,x1,x2,x3,x4,x5,x6);
writetable(T,'table.txt');
fid = fopen('table.txt', 'r') ;            
fgetl(fid) ;                                  
buffer = fread(fid, Inf) ;                  
fclose(fid);
fid = fopen('joblist.txt', 'w')  ;  
fwrite(fid, buffer) ;                         
fclose(fid) ;
delete('table.txt');
t1=toc/3600;
H=floor(t1);
t2=(t1-H)*60;
M=floor(t2);
t3=(t2-M)*60;
S=floor(t3);

%Show the run time
disp(sprintf('The run time of joblist.txt production is  %g:%g:%g',H,M,S)) 

%%% the joblist.txt based on the Sobol sequences method is on the desktop%%%
%END%

2015/09/11 17:52 · Yi Zhang

Page Tools