Write function to generate matrix

how I can write a function (function.m)file , it can generate a specific matrix such as
A=[2 5 10;-8 -1 8;12 9 2] BY use function statment function[]=NAME() ??

回答 (1 件)

Cameron
Cameron 2023 年 1 月 3 日

0 投票

This would be saved as YourFunction.m
function FunctionOutput = YourFunction(input1,input2)
%input1 is number of rows
%input2 is number of columns
FunctionOutput = rand(input1,input2);
end

3 件のコメント

ahmed
ahmed 2023 年 1 月 4 日
this will give a random matrix i want to generate exactly same matrix above
Cameron
Cameron 2023 年 1 月 4 日
Look at what I wrote, and try to make it reflect your needs.
FunctionOutput will be the specific matrix that you want - in this case A=[2 5 10;-8 -1 8;12 9 2].
YourFunction is the function you will be calling while input1 and input2 are the inputs required. But if you have a specific matrix (what you call A) then you don't need inputs. I gave them as an example.
You would set your FunctionOutput to equal to whatever you want your matrix to be.
ahmed
ahmed 2023 年 1 月 4 日
The problem has been solved ,THANK YOU

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

カテゴリ

ヘルプ センター および File ExchangeDescriptive Statistics についてさらに検索

質問済み:

2023 年 1 月 3 日

コメント済み:

2023 年 1 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by