[英]Accessing elements in matlab, get pixels of color image (array) from indices stored in another array
[英]Matlab: Get elements of Cell Array from Indices
我有一個1x84的單元格數組,可以獲取用於交叉驗證的索引:
indices = crossvalind('Kfold',length(filenames),k_fold);
for i = 1:k_fold
test = (indices == i);
train = ~test;
給定測試和訓練(1或0的84x1邏輯數組),我如何獲得所有通過測試/訓練索引的文件名?
您可以在單元格數組上應用邏輯索引以對其進行切片。 這是簡化的示例:
%# create a cell array of string
C = cellstr(num2str((1:5)', 'file %d'));
%# random split
trainIdx = rand(size(C)) > 0.5;
testIdx = ~trainIdx;
%# slice cell array
tr = C(trainIdx)
ts = C(testIdx)
請注意, tr
和ts
都是字符串本身的單元格數組。 因此,要訪問tr
的第一個字符串,您需要執行以下操作:
>> tr{1}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.