How to load vectors as input parameters and calculate results for each element in a multiscript program?

2 visualizzazioni (ultimi 30 giorni)
Hi all, I have created a multiscript program with global variables that calculates a lot of things. So far, I have 3 input parameters set as structures, one value each. So far, I load the desired numbers and do the calculations.
x = 0.25, y = 182.2, z = 45.1
Now, I want to substitute x,y,z with 3 vectors like
x = [0.25 0.50 0.75 100], y = [182.2 175.1 172.7 177.6], z = [45.1 35.8 35.7 31.7]
Then I want to run the program (many scripts) and calculate results for every element of these 3 input vectors. Namely, if I had 1 output before, now I want to have one vector with 4 elements. It should not be hard to do but I am kinda new to matlab so your help would be valuable!

Risposte (1)

Walter Roberson
Walter Roberson il 17 Set 2015
Convert at least one of your scripts into functions that take three parameters, x, y, and z. The function does not need to change to handle multiple values of x, y, and z, but it does need to return the scalar result of the calculation. For example, if before you had RunMyCode.m that expected x, y, and z to be scalar values, and it calculates MyResult, then you would change the file to
function MyResult = RunMyCode(x, y, z)
Once you have done that, have other code that creates x, y, and z as vectors. Then in that code,
OverallResults = arrayfun(@(X,Y,Z) RunMyCode(X,Y,Z), x, y, z);

Categorie

Scopri di più su Financial Data Analytics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by