필터 지우기
필터 지우기

Write a function called rand_test

조회 수: 3 (최근 30일)
Siddharth Varshney
Siddharth Varshney 2021년 12월 12일
답변: Net Fre 2021년 12월 12일
Write a function called rand_test that takes one scalar positive
integer input argument n (you do not have to check the input argument) and
returns two output arguments: a column vector of n2 elements and an n-by-n
matrix. The two output arguments must contains the exact same set of random
numbers (use rand). Here is a sample run:
>> [m v] = rand_test(2)
m =
0.4170
0.7203
0.0001
0.3023
v =
0.4170 0.0001
0.7203 0.3023
  댓글 수: 1
Siddharth Varshney
Siddharth Varshney 2021년 12월 12일
function [x, v]= rand_test(n)
x= rand(n^2,1);
v= [x,x];
end
I am not able to put code for 'v'.
Please can someone help.

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

채택된 답변

Net Fre
Net Fre 2021년 12월 12일
You can use reshape for that:
function [m v] = rand_test(n)
m = rand(n^2,1)
v = reshape(m,[n,n])
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by