How to generate dataset automatically using MATLAB

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

I don't really understand what you are asking, but I suspect you need a cell array.
Can you provide a small example with actual numbers to show the result you want?
@Rik This code generate out1,out2,out3,out4 shape of 1x4000
but i want more sample to generate automatically like the out1 has 1x50000 samples
then i divided the data in rows so that each row contains 1000 samples
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.
@Rik like out1 is one class out2 is second class, out3 is third class and out4 is fourth class
I want to generate a larger data using the above code.
the above code generate the data of only 4000 samples,
i want to generate 50000 samples for each class

Sign in to comment.

Answers (1)

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)
ans = 1×2
4 500000

17 Comments

@Rik you repeated the matrix, but i want like
prfSTG is the value and it has 800 number of samples, i am doing it manually but i want it automatically
prfSTG = [200 400 800 1000 900 ];
n_pulsesSTG = [800 800 800 800 800 800 ];
You are saying the same thing over and over again. Since I still don't understand what you want, why don't you try a different explanation?
Please explain what you want with an example. Your code doesn't actually sample from a dataset anywhere, it just replicates data. If you want some sort of sampling, you will have to explain what you want.
Did you intend to use repelem for out1 as well? Is your question how to create that n_pulsesSTG array given total_samples_per_class=5e5?
@Rik Okay let me explain it to you.
prfSTG = [200 400 800 1000 900 ]; is the value n_pulsesSTG are the sample for each value e.g 800
i am manually putting value of prfSTG and n_pulsesSTG . i want it automatically to complete total_samples_per_class
Something like this then?
total_samples_per_class=5e4;
prfSTG = [200 400 800 1000 900];
n_pulsesSTG = total_samples_per_class/numel(prfSTG) * ones(1,numel(prfSTG));
disp(n_pulsesSTG)
10000 10000 10000 10000 10000
This doesn't enforce integer values, so repelem could still result in an error for some combination of values.
%contrived example:
total_samples_per_class=8;
prfSTG = [200 400 800 1000 900];
n_pulsesSTG = total_samples_per_class/numel(prfSTG) * ones(1,numel(prfSTG));
disp(n_pulsesSTG)
1.6000 1.6000 1.6000 1.6000 1.6000
@Rik No, i think I should repost the question again for better understanding
I don't think you should. If you can't edit this question to make it clear, posting it again doesn't solve anything. You should clarify it here.
Please don't ignore my suggestion: show an example with only a few numbers. Show the input you have and what you want as a result.
@Rik Ok let me explain it .
I have class 1 which is out1 it consists of different levels like [200 400 800 1000 900 ] and every level has 800 samples. which i manually enter. I want it to automatically for all classes using rand or some other method
So should that array of 800 be generated automatically? It should not be 800 if you want 5e4 samples in total.
What exactly is your input data and what exactly is the thing that should be generated. Please answer this question. If you don't, I will not be able to help you. If you don't want help, that's fine, but don't pretend.
@Rik i just give an example with above code so that you can understand
@Rik i want 5e4 samples in total. with automatically set values of [200 400 800 1000 900]
Which vector should be automatically generated, and based on what?
@Rik based on number e.g this number i am manually putting but it should generated automatically[200 400 800 1000 900 ];
So like this?
randi(10,1,5)*100
ans = 1×5
200 300 800 600 400
Then I presume that is the answer you're looking for. If you have any remaining issues, feel free to comment.
@Rik No the problem is still remaining .
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.

Sign in to comment.

Products

Release

R2021b

Asked:

on 2 Mar 2022

Commented:

Rik
on 3 Mar 2022

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!