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 个评论
Rik
2022-3-2
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?
Med Future
2022-3-2
Rik
2022-3-2
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.
Med Future
2022-3-2
回答(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)
17 个评论
Med Future
2022-3-2
Rik
2022-3-2
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?
Med Future
2022-3-2
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)
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)
Med Future
2022-3-2
Rik
2022-3-2
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.
Med Future
2022-3-2
Rik
2022-3-2
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.
Med Future
2022-3-2
Med Future
2022-3-2
Rik
2022-3-2
Which vector should be automatically generated, and based on what?
Med Future
2022-3-3
So like this?
randi(10,1,5)*100
Med Future
2022-3-3
Rik
2022-3-3
Then I presume that is the answer you're looking for. If you have any remaining issues, feel free to comment.
Med Future
2022-3-3
Rik
2022-3-3
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!