How to find function for many parameters?

1 Ansicht (letzte 30 Tage)
Ammy
Ammy am 14 Sep. 2021
Beantwortet: Image Analyst am 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.

Akzeptierte Antwort

KSSV
KSSV am 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

Weitere Antworten (1)

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

Kategorien

Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by