我有以下代码:保存矩阵在for循环MATLAB
for c=1:10;
D = maximin(n2,n1,'euclidean');
M = min(D,[],2); ;
C=[D M];
[maxValue, rowIdx] = max(C(:,end),[],1); %max value and the row index
n1(end+1,:) = n2(rowIdx,:); %Copy selected row to bottom of n1
n2(rowIdx,:) = []; %Delete the row from n2 that has the maximin
c=c+1;
end
n1为50 * 80和n2为100 * 80在第一次迭代n1的端= 51 * 80且N 2 = 49 * 80等等。我需要在每次迭代结束时看到保存n1,以便我可以使用n1(1)... n1(10)进行进一步计算。请帮忙。我试过以下
B = cell(1, c); B(n) = n1(1, c+1); and
B{n} = n1;
没有帮助。很感谢任何形式的帮助。
感谢
你得到了什么错误信息?你在循环中放置第二块代码的位置? – kkuilla
我把它放在“c = c + 1”语句的正上方。我在使用B {n}时没有遇到错误,而是得到一个1 * 10的矩阵,其中每个单元由n(n1..n10,10个单元)组成。它像整个n1矩阵在B {n}的一个单元中 –