如何创建具有 2 个特征的随机操作?

How can I create random operations with 2 features?

示例:我有特征 Y 和特征 X。

我想让 Octave 做 Y(随机运算符)X。

然后重复此操作,但使用随机运算符,并在进行时记录结果。这可能吗?

我的尝试:

A = ['*';'+';'-';'/'];

for i:(1:10)
    op1 = A (randi([1 4]),1);
    op2 = A (randi([1 4]),1);
    op3 = A (randi([1 4]),1);
    op4 = A (randi([1 4]),1);
    op5 = A (randi([1 4]),1);
    op6 = A (randi([1 4]),1);
    result = 1 op1 4 op2 25 op3 2 op4 23 op5 6 op6 2
end

不涉及使用 evalstr2func 的可能解决方案可能是使用 anonymous functions.

的数组
% Define the input values
v1=25
v2=5
% Define the array of anonymous functions, one for each operator
f={@(x,y) (x+y);
   @(x,y) (x-y);
   @(x,y) (x*y);
   @(x,y) (x/y)}
% Randomly call one of the anonymous functions
for i=1:10
   r=randi([1,4],1,1)
   result(i)=f{r}(v1,v2)
end