How do I search these matlab cells/structures?
1 回表示 (過去 30 日間)
古いコメントを表示
I saved my experimental data in this mixture of cells and structures, but now I'm having a hard time searching in it.
first there is a cell containing animal{1,1} to animal{1,6} each contains some information strings and another cell animal{1,n}.traces{1,m} where again structures with more information and several measurements (traces) are stored for each measurement there are three regions animal{1,n}.traces{1,m}.region{1,p} the actual data points are eventually under animal{1,n}.traces{1,m}.region{1,p}.data
for clarity, please see the mat file which I uploaded here https://www.dropbox.com/sh/sn6oqsngkrby3cl/zJSqMvUVzt/data.mat
What I want to do is now to search for example for all n and m indices, which have animal{1,n}.traces{1,m}.stimulus == '1mA' and/or animal{1,n}.traces{1,m}.anesthesia == 'isofluran'
0 件のコメント
採用された回答
Ken Atwell
2012 年 7 月 5 日
Interesting problem. Since the length of traces is not consistent, and their subfields may not exist, some degree of error checking is needed. Here is a brute-force way to do this:
for n=1:numel(animal)
for m=1:numel(animal{n}.traces)
if ( isfield(animal{n}.traces{m}, 'stimulus') && ...
strcmp(animal{n}.traces{m}.stimulus, '1mA') ) || ...
( isfield(animal{n}.traces{m}, 'anesthesia') && ...
strcmp(animal{n}.traces{m}.anesthesia, 'isofluran' ) )
fprintf('animal{%d}.traces{%d} meets criteria\n', n, m);
end
end
end
Here is a second way that is arguably more elegant, but the unmitigated use of try/catch will mask other potential problems in the data:
maxM = max(cellfun(@(x) numel(x.traces), animal));
[N,M]=meshgrid(1:numel(animal),1:maxM);
M=M(:); N=N(:);
for i=1:numel(M)
try
if strcmp(animal{N(i)}.traces{M(i)}.stimulus, '1mA') || ...
strcmp(animal{N(i)}.traces{M(i)}.anesthesia, 'isofluran' )
fprintf('animal{%d}.traces{%d} meets criteria\n', N(i), M(i));
end
catch %#ok<CTCH>
end
end
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Type Identification についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!