我有一个值矩阵,如下所示。
candidate_edges =
10.0000 10.0000 6.0000
155.5000 105.5000 75.5000
25.5000 105.5000 75.5000
295.5000 415.5000 155.5000
185.5000 415.5000 155.5000
185.5000 485.5000 155.5000
195.5000 305.5000 74.5000
115.5000 305.5000 74.5000
115.5000 395.5000 74.5000
195.5000 395.5000 74.5000
25.5000 185.5000 75.5000
155.5000 185.5000 75.5000
295.5000 415.5000 5.5000
295.5000 415.5000 155.5000
185.5000 415.5000 155.5000
195.5000 305.5000 5.5000
195.5000 305.5000 74.5000
195.5000 395.5000 74.5000
295.5000 415.5000 5.5000
195.5000 395.5000 5.5000
295.5000 485.5000 5.5000
300.0000 600.0000 0
295.5000 415.5000 155.5000
185.5000 415.5000 155.5000
我想生成长度为1:length(candidate_edges)的数组,并且在每个单元格中,我想存储上述矩阵的每一行。以下是我的代码
cnode = zeros(1, n);
cnode = cell(1, n);
for k = 1:length(cnode)
for j = 1:length(candidate_edges)
cnode{k} = candidate_edges(j,:);
end
end
在输出中,我在每个单元格中只得到相同的值。
答案 0 :(得分:1)
您不需要两个循环。例如这应该做
cnode = cell(1, size(candidate_edges, 1))
for k = 1:numel(cnode)
cnode{k} = candidate_edges(k,:);
end
答案 1 :(得分:1)
你也可以使用内置的MATLAB函数 //Function to Print the name of Next Day in Javascript
var NextDay = (function () {
counter = 0;
var nextDay = function () {
var days = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday",
"Friday", "Saturday"];
var date = new Date();
var dayNumber = date.getDay() + counter;
if (dayNumber < 6) {
dayNumber = dayNumber;
}
else {
dayNumber = (dayNumber % 6);
}
var dayName = days[dayNumber];
counter += 1;
return dayName;
};
return nextDay;
})();
NextDay();
NextDay();
NextDay();
NextDay();
NextDay();
NextDay();
NextDay();
NextDay();
,如下所示:
mat2cell