Clear Filters
Clear Filters

how to find the indexing for the following code.

1 view (last 30 days)
clear all;
clc
A=[1 2;
3 4;
5 6;
7 8;
9 10;
11 12;
13 14;
15 16];
C=size(A,1)
B=1:3
D= randi(C,1)
I want to perform the randi(C,1) with respect to 1st index of B followed by 2nd index ,then 3rd index.
Could anyone please help me on this.

Accepted Answer

KSSV
KSSV on 19 Feb 2019
A=[1 2;
3 4;
5 6;
7 8;
9 10;
11 12;
13 14;
15 16];
C=size(A,1)
B=1:3
for i = B
D= randi(C,i)
end
  1 Comment
jaah navi
jaah navi on 19 Feb 2019
ok.
B=1 2 3;
But i want to have the result in the following manner
In for loop i=1
D=randi(C,1)
=8 % D should displays the single number with respect to first element of i
i=2
D=randi(C,2)
=5 % D should display the single number with respect to second element of i but not in 2x2.
i=3
D=randi(C,3)
= 4%D should display the single number with respect to third element of i but not in 3x3.
Could you please help me on this.

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!