필터 지우기
필터 지우기

How to produce two 3*3 random matix for two varible

조회 수: 2 (최근 30일)
Yode
Yode 2017년 7월 9일
댓글: KSSV 2017년 7월 9일
Of course,we can use this method
>> matrix1=randi(10,3)
matrix1 =
3 3 7
8 1 6
2 6 5
>> matrix2=randi(10,3)
matrix2 =
7 7 8
7 10 3
7 3 2
Then the variable both matrix1 and matrix2 is random matrix.But I don't like this repetition work.If I'm in Mathematica,I just run
{matrix1, matrix2} = RandomInteger[10, {2, 3, 3}]
Then I get two 3*3 matrix. Matlab can conveniently to do such thing or is there any more elegant method?

답변 (2개)

Walter Roberson
Walter Roberson 2017년 7월 9일
There is no convenient way to do this in MATLAB.
You can create a variable and use mat2cell to break it into two cell locations. You need to assign that to a variable. Then you can use deal() to split the variable by taking advantage of comma list expansion. If you were doing this more than once you would want to write a function to do it.

KSSV
KSSV 2017년 7월 9일
iwant=randi(10,3,3,2)
  댓글 수: 2
Yode
Yode 2017년 7월 9일
I know this,I just don't know how to asign the two matrix to two variable.Such as you cannot use [a,b]=randi(10,3,3,2) to get two variable.
KSSV
KSSV 2017년 7월 9일
Why you want to assign them into two different variables? There is no necessity for this.. iwant(:,:,1) and iwant(:,:,2), this is the way you use where you want.

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

카테고리

Help CenterFile Exchange에서 输入和输出参数에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!