how to find the indexing for the following code.

1 次查看(过去 30 天)
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.

采纳的回答

KSSV
KSSV 2019-2-19
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 个评论
jaah navi
jaah navi 2019-2-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by