How to find function for many parameters?

1 vue (au cours des 30 derniers jours)
Ammy
Ammy le 14 Sep 2021
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.

Réponse acceptée

KSSV
KSSV le 14 Sep 2021
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 commentaire
Ammy
Ammy le 14 Sep 2021
Thank you very much.

Connectez-vous pour commenter.

Plus de réponses (1)

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

Catégories

En savoir plus sur Data Import and Analysis dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by