簡體   English   中英

將矩陣保存在for循環matlab中

[英]Save matrix in for loop 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和n2 = 49 * 80,依此類推。 我需要在每次迭代結束時保存n1,以便可以使用n1(1)... n1(10)進行進一步的計算。 請幫忙。 我嘗試了以下

B = cell(1, c); B(n) = n1(1, c+1); and
B{n} = n1; 

沒有幫助。 很感謝任何形式的幫助。

謝謝

您應該在循環之前預先分配B ,如下所示:

B = cell(10, 1);

在循環的每次迭代中,您都將n1存儲在B如下所示:

B{c} = n1;

然后,您可以使用相同的語法訪問n1計算出的任何迭代。 例如,在第三次迭代中計算出的矩陣n1B{3}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM