运行 一个自定义程序重复直到一个矩阵的两个分量为0?

Run a self-defined program repeatedly until two components of a matrix is 0?

我对matlab完全不熟悉,而且我有一个in-class项目来完成它。

我有一个名为L1(线性程序)的自定义.m 函数。我想重复 L1 并将其中一个变量 tau 增加 2 倍,直到 w 的两个分量(一个 31x1 矩阵)为零,同时将 w 的低于阈值 [=13 的分量归零=]

我知道这是非常错误的,但我不是真正的程序员。所以我在考虑做一个 while 循环?很长的几行:

%runs program once to get values of w
tau = 0.1
fracTest = 0.1 %these are just variables
reord = 0 %more variables
[train,~,~,~] = wdbcData(input_file, dataDim, fracTest, reord); %another self-defined function
[w, gamm, obj, misclass] = separateL1(train, 1:dataDim, tau, quiet);

while w > 0
    tau = tau*2
    [train,~,~,~] = wdbcData(input_file, dataDim, fracTest, reord);
    [w, gamm, obj, misclass] = separateL1(train, 1:dataDim, tau, quiet);

    %checks threshold value
    if w < 10^-6 * norm(w, Inf) 
     w = 0
    end

end

不胜感激!

其实你做的还不错,只是稍微优化了一下,修正了一些小错误。

fracTest = 0.1 %these are just variables
reord = 0 %more variables
tau = 0.1

w = [1 1]; %set w to some non-zero value initially
while isequal(w,[0 0])
    tau = tau*2
    [train,~,~,~] = wdbcData(input_file, dataDim, fracTest, reord);
    [w, gamm, obj, misclass] = separateL1(train, 1:dataDim, tau, quiet);

    %checks threshold value
    th = 10^-6*norm(w, Inf)
    if w(1) < th 
     w(1) = 0
    end
    if w(2) < th 
     w(2) = 0
    end

end