how to make looping for random data and discrete

size = [0.35,0.45,0.8] L =rand(20,6) L = ['location',size] max = 33 min = 2
For column 1,3,5 will be detect for location and each row will be use this equation which is floor(L)*(max-min)+min.
for column 2,4,6 will be detect for size and each row will be measured as below:
if random value <0.3333 will be select size no 1 which is 0.35. if 0.3334< random value <0.6666 will be select size no 2 which is 0.45 if random value > 0.6667 will be select size no 3 which is 0.8
i already do this programming but my programming to long. so i dont know to to use looping programing or find programming to integrate with this data.
i hope you guys can help me.

Answers (1)

(You should not use the name 'size' for one of your variables, since that is the name of one of matlab's functions, so I have taken the liberty of changing it to 'sz'.)
I am having to guess about the following because I am not sure I entirely understand your description. However, if it is incorrect, perhaps you can use its ideas to develop a correct algorithm. One of my uncertainties is where you want the results to be placed. I assumed here you wanted them placed back in 'L'.
sz = [0.35,0.45,0.8];
max = 33; min = 2;
L = rand(20,6);
L(:,[1,3,5]) = floor(L(:,[1,3,5]))*(max-min)+min;
t1 = L(:,[2,4,6]) > 1/3;
t2 = L(:,[2,4,6]) > 2/3;
L(:,[2,4,6]) = (~t1)*sz(1)+(t1&(~t2))*sz(2)+t2*sz(3);

1 Comment

Thank you for your helping.this programming help me to solve my problem.

This question is closed.

Tags

Asked:

on 17 Dec 2014

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!