[英]variable number of arguments in ndgrid in MATLAB
我想生成一個參考矩陣。 此代碼有效,但我想使用可變大小的set。 我無法解決...謝謝您的幫助!
cpt = 1;
for ll = 1: 3
nb_rules = 5;
sets{cpt} = [1 : nb_rules];
cpt = cpt +1;
end
[x y z] = ndgrid(sets{:});% Here begins the trouble :
mat_ref = [x(:) y(:) z(:)];% what if size is not 3 ?
在接收端使用cell
-array GRID
獲得程序化的逗號分隔列表 :
N = numel(sets);
[GRID{1:N}] = ndgrid(sets{:});
mat_ref = reshape(cat(N+1,GRID{:}),[],N)
(無需先聲明GRID = cell(..)
。)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.