Using recursive function with combination of n variables(each variable being an array of numbers)!!

1 次查看(过去 30 天)
I have 5 variables; x, y, z, r and s.
each of these variables contains an array of data. Eg. x=[10, 20, 30, 40, 50, 60], y=[2,3,4,5,6], z=[0.5, 0.75, 1, 5, 10], r=[50, 220, 1100], s=[2, 10, 100]
conditions for the simulation to be met; x/y <= 10; r/s>50
How to run simulation for the various combination of this data set, in a single go?

回答(1 个)

Torsten
Torsten 2021-7-18
mx = size(x,2);
my = size(y,2);
mz = size(z,2);
mr = size(r,2);
ms = size(s,2);
[X,Y,Z,R,S] = ndgrid(1:mx,1:my,1:mz,1:mr,1:ms];
product = [x(:,X),y(:,Y),z(:,Z),r(:,R),s(:,S)];
product(product(:,1)./product(:,2) > 10 | product(:,4)./product(:,5) <= 50) = [];
product

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by