[英]Find index of element in cell array of matrices
我想在矩陣的單元格數組中找到特定矩陣的索引(在行和列中),例如,如果我有
A = [2 3;4 1]
和
B = {[2 2;1 1] [2 3;4 1] [1 1;1 1]}
那么我想返回2 (因為B{2}==A )。
2
B{2}==A
我想解決這個問題,而不for ,雖然我沒有到,單元陣列基本上是小,但我想這樣做不for呢。
for
我搜索了這一點,並發現這和這對SO,但他們的解決方案只針對那些沒有在這里我字符串的工作。
那么如何在沒有for循環的情況下解決這個問題呢?
A是普通矩陣而不是單元素單元格數組, B是矩陣的單元格數組。
A
B
一些可能性:
使用帶有isequal cellfun來測試B每個元素是否相等:
isequal
cellfun
find(cellfun(@(x) isequal(x,A), B))
如果所有矩陣的大小相同 :串聯成3D數組(或者更好的是,從頭開始使用3D數組),然后使用bsxfun進行比較:
bsxfun
find(all(all(bsxfun(@eq, A, cat(3, B{:})),1),2))
[英]How to find index of the last non-empty element in a cell array
[英]How do I find the maximum of each dimension in a cell array of matrices?
[英]Find index of an element in an array in PHP
[英]How to find the index of an element in an array?
[英]Find row Index of strings in cell Array (Matlab)
[英]Add cells in cell array of matrices
[英]Elementwise sum of matrices in cell array
[英]find index of array element in another array javascript
[英]Better way to find array element index?
[英]Rotate array and find index of maximum element
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.