How to find function for many parameters?

1 回表示 (過去 30 日間)
Ammy
Ammy 2021 年 9 月 14 日
回答済み: Image Analyst 2021 年 9 月 14 日
let
A=randperm(16);
A=reshape(A,4,4);
I have the following function
function [B]=fun(A,a,b,c)
B= a.*A+b.*A+c.*A
end
Now I want to find B with different parameters
a,b,c
1, 2,3
6,1,4
7,3,5
for a single set I can find [B]=fun(A,1,2,3)
but I have many parameters, is there any way to save parameters in a separte file and run the code for all these and save all the results.

採用された回答

KSSV
KSSV 2021 年 9 月 14 日
vals = [1, 2,3
6,1,4
7,3,5] ;
[m,n] =size(vals) ;
B = zeros(4,4,m) ;
for i = 1:m
B(:,:,i)=fun(A,vals(i,1),vals(i,2),vals(i,3)) ;
end
  1 件のコメント
Ammy
Ammy 2021 年 9 月 14 日
Thank you very much.

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

その他の回答 (1 件)

Image Analyst
Image Analyst 2021 年 9 月 14 日
You can use the save() function to "save parameters in a separte file" and recall them later.

カテゴリ

Help Center および File ExchangeData Import and Analysis についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by