How to generate dataset automatically using MATLAB
22 views (last 30 days)
Show older comments
Hello everyone, i hope you are doing well
i have the following code, which generate dataset,
out1,out2,out3,out4 has shape of 1x4000.
the dataset has shape of 4x4000.
I want out1,out2,out3,out4 shape to 1x50000 and
each row contain 1000 samples there is 50 rows for each out1,2,3,4,
so row shape is 1x1000
so that the output dataset shape of 200x1000.
Can anybody help me in that;
clc;clear;
prfSTG = [200 400 800 1000 900 ];
n_pulsesSTG = [800 800 800 800 800 800 ];
out1 = repmat(prfSTG,1,(ceil(sum(n_pulsesSTG)/length(n_pulsesSTG))));
prf = [200];
n_pulsesconstant = [4000];
out2 = repmat(prf,1,(ceil(sum(n_pulsesconstant)/length(n_pulsesconstant))));
out3 = (rand(1,4000)*100)+750;
val = [200,500,800,1000,800,900,700,300,600,150];
num = [120,400,830,400,300,450,200,400,500,400];
out4 = repelem(val,num);
%Create a Dataset
dataset = [out1; out2; out3; out4];
4 Comments
Rik
on 2 Mar 2022
So you just want to repmat your out variables by a factor 12.5? You will have to choose how to deal with the fact that you don't have an integer multiple you want to end up with.
I also suspect you would be interested in reshape to get your desired shape.
I have no clue what you're attempting to do. Your variable names are mostly meaningless to me and you don't have any comments, so the code is no help to me.
Answers (1)
Rik
on 2 Mar 2022
Maybe you want this?
total_samples_per_class=5e5;
prfSTG = [200 400 800 1000 900 ];
n_pulsesSTG = [800 800 800 800 800 800 ];
out1 = repmat(prfSTG,1,total_samples_per_class/numel(prfSTG));
prf = [200];
n_pulsesconstant = [4000];
out2 = repmat(prf,1,total_samples_per_class/numel(prf));
out3 = (rand(1,total_samples_per_class)*100)+750;
val = [200,500,800,1000,800,900,700,300,600,150];
num = [120,400,830,400,300,450,200,400,500,400];
out4 = repelem(val,num);
out4 = repmat(out4,1,total_samples_per_class/numel(out4));
%Create a Dataset
dataset = [out1; out2; out3; out4];
size(dataset)
17 Comments
Rik
on 3 Mar 2022
Those two statements are contradictory. Either you needed a vector like the one produced by randi, or you didn't. Which is it?
Please start explaining what you have and what you want. Which vector should be generated, based on what? You really need to answer that properly. If you don't want help, just say so. If you do actually want help, provide the required information.
See Also
Categories
Find more on Matrices and Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!