【发布时间】:2014-11-15 20:25:02
【问题描述】:
我有两个向量,v1 (1x9) 和 v2 (1x4)。
我必须编写一个有两个输入的函数,(x,y) 和out 的输出。
x 应该是v1 中的索引号x。
y 应该是v2 中的索引号y。
该函数应将v2 中的xth 元素替换为v1 中的yth 元素,并将新的v2 作为输出。
举个例子:
v1=[1 2 3 4 5 6 7 8 9];
v2=[1 2 3 4];
out = myfun(7,2);
那么输出应该是
out = [1 7 3 4];
下次如果x=9和y=1
out = myfun(9,1);
out = [9 7 3 4];
我的主要程序想法是
[M Z]=测试(A,q) A 是矩阵 (mxn) q 是长度为 m 的向量 i=[1:m];j=[1:n]; c(:,j)=q./A(:,j); 在 c 中找到最小元素。例如它是 c(I,j) 然后 x=我;和 y=j;g i = [1:x-1,x+1:m]; j = [1:y-1,y+1:n]; % 开始新的计算 语句...计算过程以找到矩阵 M 而不是 A 和向量 Z 而不是 q。
程序结束
现在我想编写你之前在这个程序中所做的 myfunction
elseif v(x) <= v1(n) this program must working continuously (holding M and Z as new A and q in input and get the minimum ratio and so the new x and y ) until v(x)==n break
请帮忙
【问题讨论】:
-
v2(y) = v1(x);不是你想要的?