k = 1; %2cm for i = 1:1000 str = sprintf('images/2cm/%d.jpg', i); image_to_store = imread(str); database(:,:,1,k) = (image_to_store(:,:)); % images are in grey scale labels(k) = 2; k = k+1; end %20cm for i = 1:1000 str = sprintf('images/20cm/%d.jpg', i); image_to_store = imread(str); database(:,:,1,k) = (image_to_store(:,:)); labels(k) = 20; k = k+1; end % ...
Hope this does what you wanted:
% Your data set: % The first 1000 entries with labels 2cm, % The second 1000 entries with labels 20cm, database = rand(28,28,1,2000); % percentage of training points = 70%, validation = 30%, test = 0% p=0.7; % One way to divide the 2000 database entries [trainInd,valInd,testInd] = dividerand(2000,p,1-p,0); trainDatabaseBad = database(:,:,:,trainInd); valDatabaseBad = database(:,:,:,valInd); size(trainDatabaseBad) % output: 28 28 1 1400 size(valDatabaseBad) % output: 28 28 1 600 % A better way to divide, which ensures that % there is equal propotion of 2cm to 20cm samples in % the training set, validation set, and the whole set [trainInd1,valInd1,testInd1] = dividerand(1000,p,1-p,0); [trainInd2,valInd2,testInd2] = dividerand(1000,p,1-p,0); trainDatabase = cat(4, database(:,:,:,trainInd1), database(:,:,:,trainInd2)); valDatabase = cat(4, database(:,:,:,valInd1), database(:,:,:,valInd2)); size(trainDatabase) % output: 28 28 1 1400 size(valDatabase) % output: 28 28 1 600
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.