필터 지우기
필터 지우기

I want to generate different combinations of amplitudes. let say 10k random combinations. i am new to matlab, anyone who can help, how to generate it.

조회 수: 4 (최근 30일)
clear all;
clc;
f0=1/(2*pi);%initial frequency of dipoles
% x_probe=5;%x coordinates of reciever point
% y_probe=5;%x coordinates of reciever point
N=400; % number of dipoles in the area
a = 0.5; % width along x
b = 0.5; % height along y
x=a*rand(1,N); % random coordinates of dipoles
y=b*rand(1,N);
xmin=0;xmax=0.5;
ymin=0;ymax=0.5;
Xpoints=400;Ypoints=400;
xg=linspace(xmin,xmax,Xpoints);yg=linspace(ymin,ymax,Ypoints);
[Xi,Yi]=meshgrid(xg,yg);
Rx=reshape(Xi,[length(xg)*length(yg) 1]);
Ry=reshape(Yi,[length(xg)*length(yg) 1]);
amp(1:N)=0;% amplitude of emmiting dipoles
amp(1)=1; % 2 dipoles emitting (relative amplitude)
amp(2)=0.75;
amp(3)=0.5;
amp(4)=0.5;
amp(5)=1;
x(1)=0; % x coordinates of 1 dipole that emits
y(1)=0.05; % y coordinates of 1 dipole that emits
x(2)=0; % x coordinates of 1 dipole that emits
y(2)=0.10; % y coordinates of 2nd dipole that emits
x(3)=0;
y(3)=0.15;
x(4)=0;
y(4)=0.20;
x(5)=0;
y(5)=0.25;
x_probe=5;%x coordinates of reciever point
y_probe=3.5;%x coordinates of reciever point
x_probe1=5;
y_probe1=2.5;
x_probe2=5;
y_probe2=1.5;
x_probe3=5;
y_probe3=0.5;
%resonant freq and external excitation set
fres(1:N)=f0;%constant resonant frequency
loss = 0;
rw(1:N)=loss; % absorption losses
% frequency steps selected
fmin=0.2;fmax=1.3;fstep=(fmax-fmin)/401;
f_mult=fmin:fstep:fmax; % frequency range (multiplier)
f=f_mult*f0; % frequency range
scatter(x,y,'rv','filled')
hold on
scatter(x_probe,y_probe,'gs','filled')
scatter(x_probe1,y_probe1,'gs','filled')
scatter(x_probe2,y_probe2,'gs','filled')
scatter(x_probe3,y_probe3,'gs','filled')
scatter(x(1:5),y(1:5),'bo','filled')
hold off

답변 (1개)

Nehemiae
Nehemiae 2023년 3월 9일
Hello,
To generate a random set of amplitudes, the “rand” function can be used. This generates a random number from the uniform distribution in the interval (0, 1), which is essentially what is needed as it is the relative amplitude. The number of random numbers generated depends on the matrix dimensions given to the function, which can be (1, N) to generate N random numbers.
N = 400; % Number of dipoles in the area
% Random coordinates of dipoles
x = a * rand(1, N);
y = b * rand(1, N);
amp = rand(1, N); % Amplitude of emmiting dipoles
% Random coordinates of reciever point
x_probe = a * rand(1, N);
y_probe = b * rand(1, N);
scatter(x, y, 'rv', 'filled')
hold on
scatter(x_probe, y_probe, 'gs', 'filled')
hold off
The documentation on “rand” function (https://www.mathworks.com/help/matlab/ref/rand.html) is helpful in this regard.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by