Effacer les filtres
Effacer les filtres

select random numbers from a group

4 vues (au cours des 30 derniers jours)
mukesh meharda
mukesh meharda le 30 Juil 2020
Commenté : the cyclist le 3 Août 2020
I had number of EV in different time stamp in each time, and a group of their battery capacity and type of it. first randomly divide number of EVs in 2nd column as
for i=1:24
N_EV(i)= randi(15,1,1); % not more than 15
end
Now I had Cap=[2,4,6];
so for each EVs , select a random Cap from this Cap as shown in 4th column,
Then based on logic in 6th column based on Cap value define their type of EVs
  1 commentaire
Sriram Tadavarty
Sriram Tadavarty le 30 Juil 2020
Whats your question here? Can you update the question with the data set, the code you tried, place where you struck or getting incorrect outputs?

Connectez-vous pour commenter.

Réponses (1)

the cyclist
the cyclist le 30 Juil 2020
I think I understand at least part of your question.
Do you have the Statistics and Machine Learning Toolbox? If so, then to select 4 EV from set of Caps [2,4,6], you can do
randsample([2,4,6],4)
  2 commentaires
mukesh meharda
mukesh meharda le 31 Juil 2020
thanks for your help and I solved it as below that I need......
B_Cap = [2;4;6];
for i=1:24
N_EV(i)= randi(15,1,1);
end
cell=cell(24,1);
for i=1:24
for j=1:N_EV(i)
pos(j) = randi(length(B_Cap));
cap(j) = B_Cap(pos(j)); % capacity selection for each EVs
end
cell{i,1} = cap;
pos=[];
cap=[];
end
% SoCi defining for each EVs based on their type
for i=1:24
for j=1:N_EV(i)
if cell{i,1}(j)==2
cell{i,2}(j)=0.2; %if 2W then SoCi
else if cell{i,1}(j) ==6
cell{i,2}(j)= 0.3; %if 3W then SoCi
else cell{i,2}(j)= 0.25; %if eR then SoCi
end
end
end
end
the cyclist
the cyclist le 3 Août 2020
I'm glad you found a solution.
I strongly recommend against using cell as a variable name, since it is a MATLAB function. This is a very confusing line of code:
cell=cell(24,1);
for anyone trying to understand what you are doing, and is also prevents future use of cell() as a function.
It's better to give that variable a meaningful name.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Random Number Generation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by