How to create the random sampling matrix for a certain number of times?

4 visualizaciones (últimos 30 días)
S Priya
S Priya el 24 de Feb. de 2022
Editada: Awais Saeed el 24 de Feb. de 2022
I need to find random sample(consisting of 40 values) for 16 elements (each different).Using Em22(:,:,i) will help?How to do it?
c=1;
d=20;
y11=c+(d-c)*rand(20,1);
y12=c-(d-c)*rand(20,1);
y=[y11;y12];
Em1=(432*10^6+y*10^6);
for k=1:40
Em11(k)=Em1(k,1); %Elastic Modulus(40 random values)for 1 element
Em22(:,:,i)=Em11(:,:,i); %Elastic Modulus for all elements(Doubt)
end
  2 comentarios
Arif Hoq
Arif Hoq el 24 de Feb. de 2022
I am not so much clear about your expectation.just try this
c=1;
d=20;
y11=c+(d-c)*rand(20,1);
y12=c-(d-c)*rand(20,1);
y=[y11;y12];
Em1=(432*10^6+y*10^6);
for k=1:40
Em11(k)=Em1(k,1); %Elastic Modulus(40 random values)for 1 element
Em22(:,k)=Em11(k); %Elastic Modulus for all elements(Doubt)
end
Em22'
S Priya
S Priya el 24 de Feb. de 2022
Thank you for the answer. Now the values which I am getting for Em22 is for 1 element, I want Em22 matrix (40x1) with 16 elements. (With each Em22 different from one another.)

Iniciar sesión para comentar.

Respuestas (1)

Awais Saeed
Awais Saeed el 24 de Feb. de 2022
Editada: Awais Saeed el 24 de Feb. de 2022
What I understood is that you want those 40 values with 16 different c and d, right? If yes, then loop through those values, do your calculations and store it in a multi-dimensional array.
c = [1 2];
d = [20 21];
% loop through c and d
for idx = 1:1:length(c)
y11 = c(idx)+(d(idx)-c(idx))*rand(20,1);
y12 = c(idx)-(d(idx)-c(idx))*rand(20,1);
y = [y11;y12];
Em1 = (432*10^6+y*10^6);
for k=1:40
Em11(k) = Em1(k,1); %Elastic Modulus(40 random values)for 1 element
Em22(:,k,idx) = Em11(k); %Elastic Modulus for all elements(Doubt)
end
end
Em22(:,:,1); % for first element
Em22(:,:,2); % for second element
  2 comentarios
S Priya
S Priya el 24 de Feb. de 2022
Editada: S Priya el 24 de Feb. de 2022
Thank for the answer but I donot want 40 values with 16 different c and d.
Whatever values I have for Em11(40 random values), those are for 1 element.
I want Em11 matrix for 16 different elements.
Awais Saeed
Awais Saeed el 24 de Feb. de 2022
You can store Em11 for one element in Em22(:,:,1) and Em11 for another element in Em22(:,:,2) and so on. To access Em22 for first element, just use Em22(:,:,1). I have updated the script for more clarity.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Identification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by