Repeat resampling with replacement process several times

Hello,
I have the below code for resampling with replacement.
res1 = [];
res2 = [];
% centerd matrix size:2X7
cen1=centered(1,:);
cen2=centered(2,:);
for j=1:7
res1_temp=cen1(randi(7,1));
res1= [res1 res1_temp];
%
res2_temp=cen2(7,1));
res2= [res2 res2_temp];
end
res_total=[res1; res2]; % 2X7
Now I have to repeat this process 170 times because centered matrix size is 170X7. That is, must have
re1=[];
res2=[];
.......
res170[];
......
res_total=[res1;res2,.....
res170];
and the res_total should be 170X7. How can I as easy as possible?

 Respuesta aceptada

VBBV
VBBV el 21 de Nov. de 2022
Editada: VBBV el 21 de Nov. de 2022
res1 = [];
res2 = [];
centered = rand(170,7)
centered = 170×7
0.6558 0.6340 0.7993 0.3911 0.8091 0.8170 0.1949 0.9049 0.7951 0.6934 0.1121 0.0001 0.1897 0.4469 0.3652 0.0276 0.8570 0.7298 0.7666 0.3056 0.2107 0.9367 0.4151 0.2733 0.7628 0.5691 0.6688 0.8626 0.6983 0.4839 0.8889 0.4091 0.7523 0.3580 0.3595 0.9022 0.9422 0.6523 0.8360 0.9986 0.3244 0.6809 0.0640 0.9521 0.1633 0.6885 0.4294 0.0889 0.3304 0.5681 0.7248 0.8518 0.8903 0.8060 0.3555 0.2800 0.3060 0.6259 0.1338 0.7183 0.2156 0.2771 0.4144 0.2730 0.7219 0.0963 0.6360 0.6344 0.2485 0.8829
% centerd matrix size:2X7
% cen1=centered(1,:);
% cen2=centered(2,:);
for j=1:85
cen1 = centered(j,:);
res1(j,:) = cen1;
%
cen2 = centered(j+85,:);
res2(j,:) = cen2;
end
res_total=[res1; res2] % 2X7
res_total = 170×7
0.6558 0.6340 0.7993 0.3911 0.8091 0.8170 0.1949 0.9049 0.7951 0.6934 0.1121 0.0001 0.1897 0.4469 0.3652 0.0276 0.8570 0.7298 0.7666 0.3056 0.2107 0.9367 0.4151 0.2733 0.7628 0.5691 0.6688 0.8626 0.6983 0.4839 0.8889 0.4091 0.7523 0.3580 0.3595 0.9022 0.9422 0.6523 0.8360 0.9986 0.3244 0.6809 0.0640 0.9521 0.1633 0.6885 0.4294 0.0889 0.3304 0.5681 0.7248 0.8518 0.8903 0.8060 0.3555 0.2800 0.3060 0.6259 0.1338 0.7183 0.2156 0.2771 0.4144 0.2730 0.7219 0.0963 0.6360 0.6344 0.2485 0.8829

3 comentarios

I understood what you suggested above, but I tried to do it like this:
for j=1:170
res_total(j,:)=centered(randi(j,:))
end
But it does not work.
May be you mean this instead
% res1 = [];
% res2 = [];
centered = rand(170,7);
for j=1:170
res_total(j,:)=centered(randi(j),:);
end
res_total
res_total = 170×7
0.4400 0.2235 0.8825 0.6564 0.4160 0.3429 0.0489 0.4400 0.2235 0.8825 0.6564 0.4160 0.3429 0.0489 0.0892 0.7041 0.9296 0.5553 0.7713 0.8969 0.5811 0.4400 0.2235 0.8825 0.6564 0.4160 0.3429 0.0489 0.0892 0.7041 0.9296 0.5553 0.7713 0.8969 0.5811 0.0892 0.7041 0.9296 0.5553 0.7713 0.8969 0.5811 0.1172 0.3186 0.5401 0.9210 0.5579 0.0420 0.7755 0.7331 0.6314 0.0854 0.2315 0.7209 0.7810 0.0977 0.8592 0.8540 0.0853 0.2848 0.9761 0.5497 0.2875 0.7331 0.6314 0.0854 0.2315 0.7209 0.7810 0.0977
It works!!!! Thanks for the valuable help!!!!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 21 de Nov. de 2022

Comentada:

el 21 de Nov. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by