带有for循环inplementation的matlab高数组

时间:2017-04-04 21:56:37

标签: arrays matlab datastore

我正在使用大文件(30GB +)中的二进制数据。 我已经使用自定义读取函数实现了fileDatastore。

fds = fileDatastore(location,'ReadFcn',@readFile);

readFile函数一次一个字节地将二进制数据读入一个数组。 然后我从fileDatastore创建一个高数组。

data = tall(fds);

这一切似乎都运转正常。现在我想通过高数组搜索一个字节模式(例如25后跟30)。有点像...

for i=1:size(data)
    if data(i) == 25 && data(i+1) == 30
        disp('do something')
    end
end

这似乎不可能。我最终得到了“从高处转换为逻辑不可能”的错误。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:2)

正如excaza所提到的,问题在于尽管data(i) == 25有效,但它没有返回布尔值。所以你不能申请&&运营商。 简单的解决方案似乎是嵌套if语句......

if data(i) == 25 
   if data(i+1) == 30
        disp('do something')
    end
end

答案 1 :(得分:0)

基本上,您需要做的是迭代数据的子集,因为它太多而无法放入内存中。例如,如果您设置

y = gather(data(1:100))

然后你可以在y而不是数据上进行比较。重要的一点是y必须适合记忆,而data则不能。所以你可能不能(例如)设置

y = gather(data)

答案 2 :(得分:0)

问题是您不能将高逻辑作为循环语句中的条件使用。这就是为什么错误是“无法从高处转换为逻辑”。因此,import { createStore, combineReducers, applyMiddleware } from 'redux'; import { polyglotReducer } from 'redux-polyglot'; const rootReducer = combineReducers({ polyglot: polyglotReducer }); const polyglotMiddleware = createPolyglotMiddleware( 'ACTION_TO_CATCH', action => action.payload.locale, locale => new Promise(resolve => { // perform async here resolve({ hello: 'bonjour', }); }), ) const store = createStore(rootReducer, {}, applyMiddleware(polyglotMiddleware)); export default store; 返回高逻辑,您只需使用data(i) == 25将其转换为内存逻辑。试试这个(因为同时收集它们可能更有效):

gather
  

来源:   http://www.mathworks.com/help/matlab/import_export/deferred-evaluation-of-tall-arrays.html

     

“例如,您无法控制使用高逻辑数组的if或while循环语句,但是一旦使用它来计算数组   成为您可以在这些中使用的内存中逻辑值   上下文“。