필터 지우기
필터 지우기

calling more than 2 matrix for for loop

조회 수: 1 (최근 30일)
sampath kumar punna
sampath kumar punna 2019년 10월 26일
댓글: David Hill 2019년 10월 26일
A =
8 9
15 39
23 14
18 2
13 17
40 18
14 39
38 42
x1= A([1,2,3,5,8],:)
x2= A([1,2,3,4,8],:)
x3=A([1,2,3,5,7],:)
x4=A([1,2,3,4,5,8],:)
can i have a for loop which can call x1, x2,x3,x4 in an order
  댓글 수: 2
David Hill
David Hill 2019년 10월 26일
I am not sure what you mean, please explain more fully.
sampath kumar punna
sampath kumar punna 2019년 10월 26일
x1 =[
8 9
15 39
23 14
13 17
38 42]
x2 =[
8 9
15 39
23 14
18 2
38 42]
x3 =[
8 9
15 39
23 14
13 17
14 39]
x4 =[
8 9
15 39
23 14
18 2
13 17
38 42]
i have 4 matrices i want to call each matrix to get divided by 2
which is something like this
for i=1: 4
y(i)= x(i)/2
end
but this for loop is is not working beacuse location of x1,x2,x3,x4 is not fixed.

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

채택된 답변

David Hill
David Hill 2019년 10월 26일
Why not make a cell array?
x{1}= A([1,2,3,5,8],:);
x{2}= A([1,2,3,4,8],:);
x{3}=A([1,2,3,5,7],:);
x{4}=A([1,2,3,4,5,8],:);
for i=1:4
y{i}=x{i}/2;
end
  댓글 수: 2
sampath kumar punna
sampath kumar punna 2019년 10월 26일
thanks for the answer but its not working
David Hill
David Hill 2019년 10월 26일
Maybe I misunderstood you, it works for me and produces a cell array (y) having matrix elements that are the elements of x divided by 2.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by