How to produce Gaussian random variable between two vectors ?
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
charu shree
am 3 Mai 2023
Bearbeitet: Walter Roberson
am 4 Mai 2023
Hello all, I am having two vectors:
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
I want to generate Gaussian random variable (rv) between corresponding source and target so that we get 9 different Gaussian rv i.e., first rv between 1 and 2, second rv between 2 and 3, third rv between 2 and 6 and so on.
This is what I had tried so far:
clc;
clear all;
close all;
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
for i = 1:length(sr)
for j = 1:length(ta)
nrm_rv1 = random('norm', 0, sqrt(2)); %generate Gaussian (Normal) RV
end
end
But I am not getting how to arrange nrm_rv1 so as to get 9 different Gaussian rv.
Any help in this regard will be highly appreciated.
0 Kommentare
Akzeptierte Antwort
Torsten
am 3 Mai 2023
Bearbeitet: Torsten
am 3 Mai 2023
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
for i = 1:numel(sr)
pd{i} = makedist('Normal',0, sqrt(2)); %generate Gaussian (Normal) RV
end
pd
If you mean something else when you write "I want to generate Gaussian random variable (rv) between corresponding source and target", please explain it in more detail.
3 Kommentare
Torsten
am 4 Mai 2023
Bearbeitet: Torsten
am 4 Mai 2023
I don't know what you want to do with the 9 normal distributions.
Here are some gimmicks:
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
for i = 1:numel(sr)
pd{i} = makedist('Normal',0, sqrt(2)); %generate Gaussian (Normal) RV
end
random(pd{1})
cdf(pd{4},0.5)
pdf(pd{6},4)
Did you study this ?
Weitere Antworten (1)
Luca Ferro
am 3 Mai 2023
Bearbeitet: Luca Ferro
am 3 Mai 2023
I would do it like this (assuming i understood correctly):
sr = [1,2,2,2,3,3,3,4,5]; % various possible source
ta = [2,3,6,8,6,4,7,6,6]; % various possible targets
for ii = 1:size(sr,2) %assuming that sr and ta have the same dimension
lowThs=min(sr(ii),ta(ii));
highThs=max(sr(ii),ta(ii));
nrm_rv1(ii) = lowThs+abs(lowThs-highThs)*rand(1,1);
end
i'll break it down:
- lowThs is the lowest number of the 2 in the array (i assumed no masking is done to assure that the sr value is higher than the ta value)
- highThs is the highest, same reasoning
- rand(1,1) generates a random number between 0 and 1
- abs(lowThs-highThs) this gets the span of the range between the 2 numbers low/highThs
- abs(lowThs-highThs)*rand(1,1); so by doing this we get a random number from 0 to the span
- lowThs+abs(lowThs-highThs)*rand(1,1); by adding the lowThs we get a random number that spans from lowThs to lowThs+the random number in the spane, meaning from lowThs to highThs
- nrm_rv1(ii) this is just to store it in an array. First element is random between the first couple, second between the second and so on
Note that this code works even if ta>sr and ta==sr so that you have freedom on the source arrays. The only constraint is that they must have the same dimension. If you would like to have freedom in that as well just ask, i'll gladly fix the code.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Random Number Generation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!