フィルターのクリア

Creating matrix with different elements

1 回表示 (過去 30 日間)
M.R. Ebrahimi
M.R. Ebrahimi 2020 年 11 月 12 日
コメント済み: Ameer Hamza 2020 年 11 月 12 日
Hi
I have to create a 3 * 4 matrix whose elements are between 3 and 8, but the element of each row will be different. How can I creat it?

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
編集済み: Ameer Hamza 2020 年 11 月 12 日
This is one way
lb = 3;
ub = 8;
M = rand(3,4);
for i = 1:size(M,1)
M(i,:) = randperm(ub-lb+1, size(M,2))+lb-1;
end
Result
>> M
M =
4 5 8 6
3 6 7 8
7 3 6 8
  2 件のコメント
M.R. Ebrahimi
M.R. Ebrahimi 2020 年 11 月 12 日
Thank you
Ameer Hamza
Ameer Hamza 2020 年 11 月 12 日
I am glad to be of help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by