使用Matlab为循环中的变量赋值

时间:2016-08-17 14:20:50

标签: arrays matlab

我正在学习Matlab,我正在编写一个代码,根据使用'if'的条件查找特定值。可以很容易地找到该值,但我想知道这个值是由数组A和B的哪些元素创建的。不幸的是,我无法使用此代码。我非常感谢你的关注。

.test { color : lighten( red, 10% ); }

1 个答案:

答案 0 :(得分:0)

将位置保持为k和f并参考

for m=1:L-1
  for n=m:L
     if(A(m)./B(n)> 0.09 && A(m)./B(n)<c)
        c=A(m)./B(n);
        k=m; %keeping the position
        f=n; %keeping the position
        end
     end
 end

if (f==0 || k==0) %if f or k is zero
    fprintf('No solution found\n')    
else
    fprintf('the c value is %0.5f \n',c)
    fprintf('the A(m) value is %0.5f at position %i  \n',A(k),k)
    fprintf('the B(n) value is %0.5f at position %i  \n',A(f),f)
end
相关问题