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