根據交錯模式對清單或列重新排序我指的是舊的隔行掃描視訊技術中的隔行掃描,其中螢幕上的像素線將以每隔兩行或每三行的交替模式呈現。 ( https://en.wikipedia.org/wiki/Interlaced_video有一個很好的過程 gif)
所以如果你有行(1,2,3,4,.....99)
它們將以行的順序渲染(因子 2)(1,3,5,7......97,99,2,4,6,.....98)
或(因子 3)作為行(1,4,7.....2,5,8.....3,6,9...)
我正在嘗試編寫腳本,該腳本將使用 JSL 根據此模式對任意長度的序列進行重新排序,但我不太清楚如何建立索引來對其進行重新排序。我目前正在嘗試計算矩陣數學來完成此任務,但也許 for 迴圈會更聰明/更容易?
// Create arbitrary sequence
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,21,22,23,24,25,26,27,28];
f = 3 // interlacing factor<BR />
//Start trying to work out an index or grouping for a future sorting op
b = mod(a+f-1),3);
//b = [0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 0, 1, 2, 2, 0, 1, 2, 0, 1, 2, 0]<BR />
// ????
自動化和腳本編寫回复:根據交錯模式重新排序列表或列嗨,凱西,
你是對的——我很抱歉! 試試這個代碼,它在初始轉置之前將額外的值設置為 missing ,這樣它們可以在以後用 Loc() 清除。
Names Default To Here(1);
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27];
fact = 3;
x = shape(a, ceiling(nrow(a)/fact));
try(x[(nrow(a)+1)::(nrow(x)*ncol(x))] = .);
x = shape(x`, 1);
x = x[loc(!ismissing(x))];
回复:根據交錯模式重新排序列表或列
[1::nrow(a)]
刪除第二個形狀之後的環繞位置,因此不幸的是錯誤的值被截斷了。
我用你給我的東西來標記環繞值(在這種情況下為 0,但也許 NaN 或其他東西會更好?)以便在操作結束時可以輕鬆識別和刪除它們。 我知道我使用了太多變量,請忽略草率。
n = 28; // Number of rows
f = 3; // Interlacing factor (how many scans per frame)
q = ceiling(n/f);
r = q*f;
a = 1::r;
a[loc(a > n)] = 0; //a = [1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 0 0];
s = shape(shape(a, q)`,1); //s = [1 4 7 10 13 16 19 22 25 28 2 5 8 11 14 17 20 23 26 0 3 6 9 12 15 18 21 24 27 0];
b = s[loc(s)]; //b = [1 4 7 10 13 16 19 22 25 28 2 5 8 11 14 17 20 23 26 3 6 9 12 15 18 21 24 27];
show(b);
c = [];
For(i = 1, i <= nrow(b), i++,
c = c || a`[i] || b[i];
);
show(c`); //c` gives a vector to copy/paste into a match() function that will translate progressive rows to interlaced rows
回复:根據交錯模式重新排序列表或列幸運的是,我仍然安裝了 JMP14,所以我可以對其進行測試。 一種“解決方法”是這樣的:
Names Default To Here(1);
// Create arbitrary sequence
a = Transpose(1::30);
f = 3;
b = AsList(Mod(a+f-1,f));
m_interlaced = [];
For(i = 0, i <= f-1, i++,
m_interlaced = m_interlaced |/ a[Loc(b, i)];
);
show(m_interlaced);
//m_interlaced = [1, 4, 7, 10, 13, 16, 19, 22, 25, 28, 2, 5, 8, 11, 14, 17, 20, 23, 26, 29, 3, 6, 9, 12, 15, 18, 21, 24, 27, 30];
回复:根據交錯模式重新排序列表或列在 JMP14 中,這返回“Argument should be list”,我相信指的是在 Loc 函數中調用 b 的位置。 我試圖用 as list() 修改 b 但我不明白結果。
另外,|/ 是做什麼的,它與 concat 運算符 || 有關係嗎?
a = 1::30;
f = 3;
b = as list(Mod(a+f-1,f));
m_interlaced = [];
For(i = 0, i <= f-1, i++,
m_interlaced = m_interlaced |/ a[Loc(b, i)];
);
show(m_interlaced);
/*:
m_interlaced = [](0, 1);
回复:根據交錯模式重新排序列表或列這似乎得到了正確的矩陣(如果起始矩陣的構建方式不同,可能需要轉置)
Names Default To Here(1);
// Create arbitrary sequence
a = 1::30;
f = 3;
b = Mod(a+f-1,f);
m_interlaced = [];
For(i = 0, i <= f-1, i++,
m_interlaced = m_interlaced |/ a[Loc(b, i)];
);
show(m_interlaced);
Names Default To Here(1);
// Create arbitrary sequence
a = 1::99;
f = 2;
b = Mod(a+f-1,f);
m_interlaced = [];
For(i = 0, i <= f-1, i++,
m_interlaced = m_interlaced |/ a[Loc(b, i)];
);
show(m_interlaced);
回复:根據交錯模式重新排序列表或列編輯#2:遠低於不正確。 此代碼應該工作:
Names Default To Here(1);
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27];
fact = 3;
x = shape(a, ceiling(nrow(a)/fact));
try(x[(nrow(a)+1)::(nrow(x)*ncol(x))] = .);
x = shape(x`, 1);
x = x[loc(!ismissing(x))];
////////////////////////
#EDIT:我不得不在末尾添加一個索引,以防止當因子沒有平均劃分行數時“重新開始”
/////////////
你好,
查看 Shape() 命令。 隨著轉置,你可以得到你想要的——
Names Default To Here(1);
a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,21,22,23,24,25,26,27,28];
fact = 3;
shape(shape(a, ceiling(nrow(a)/fact))`, 1)`[1::nrow(a)]
乾杯,
布雷迪