Hi a question please: o1=100 o2=200 I want to write something like that:
if true
for i=randi(O1,[1 ((50/100)*O1)])
for j=randi(O2,[1 ((50/100)*O2)])
end
in fact, if
IDX=randi(O1,[1 ((50/100)*O1) and JDX=randi(O2,[1 ((50/100)*O2)])
I want to start from IDX(1):IDX(end). like:
for i=IDX(1):IDX(end)
for j=JDX(1):JDX(end)
Thank you

답변 (1개)

Walter Roberson
Walter Roberson 2015년 11월 3일

0 개 추천

for i = IDX
for j = JDX
...
end
end

댓글 수: 4

fatema saba
fatema saba 2015년 11월 3일
Thank you. but I got the error:
Warning: Size vector should be a row vector with integer elements.
Walter Roberson
Walter Roberson 2015년 11월 3일
편집: Walter Roberson 2015년 11월 8일
IDX = randi(O1,[1 O1/2]);
JDX = randi(O2,[1 O2/2]);
Provided that O1 and O2 are even.
fatema saba
fatema saba 2015년 11월 3일
But I still get the error
Warning: Size vector should be a row vector with integer elements.
Walter Roberson
Walter Roberson 2015년 11월 8일
I do not get that. Have you possibly changed your O1 or O2 to values that are not even? Your question asked about O1=100 O2=200 both of which are even (divisible by 2).
If one of your O1 or O2 are odd, then you need to clarify whether you want the half rounded down or rounded up. For example if your O1=101 then do you want your random vector to be length 50 (101/2 rounded down) or 51 (101/2 rounded up) ?

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

2015년 11월 3일

댓글:

2015년 11월 8일

Community Treasure Hunt

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

Start Hunting!

Translated by