मुझे मिश्रित प्रकार - स्ट्रिंग्स और युगल के टैब्यूलर डेटा की बड़ी मात्रा में संसाधित करने की आवश्यकता है। एक मानक समस्या, मुझे लगता है। Matlab में इस के साथ काम करने के लिए सबसे अच्छी डेटा संरचना क्या है?मैटलैब डेटा संरचना - समय क्या है + अंतरिक्ष कुशल?
सेलरेरे निश्चित रूप से उत्तर नहीं है। यह अत्यंत स्मृति अक्षम है। (नीचे दिखाए गए परीक्षण)। डेटासेट (आंकड़े टूलबॉक्स से) बहुत समय और अंतरिक्ष अक्षम है। यह मुझे संरचनाओं या सरणी की संरचना के साथ छोड़ देता है। मैंने नीचे दिए गए समय और स्मृति दोनों के लिए चार अलग-अलग विकल्पों में एक परीक्षण किया और ऐसा लगता है कि मेरे द्वारा परीक्षण की जाने वाली चीज़ों के लिए सरणी की संरचना सबसे अच्छा विकल्प है।
मैं मैटलैब के लिए अपेक्षाकृत नया हूं और यह थोड़ा निराशाजनक है। वैसे भी - इस बारे में सलाह की तलाश है कि मुझे कुछ याद आ रहा है, या यदि मेरे परीक्षण सटीक/उचित हैं। क्या मैं एक्सेस/रूपांतरण/मेमोरी उपयोग के अलावा अन्य विचारों को याद कर रहा हूं, जो इस सामग्री का उपयोग करके कोड को और अधिक होने की संभावना है। (fyi R2010b का उपयोग कर रहा हूँ)
* * टेस्ट # 1: एक्सेस गति डेटा आइटम तक पहुंच।
cellarray:0.002s
dataset:36.665s %<<< This is horrible
structarray:0.001s
struct of array:0.000s
* * टेस्ट # 2: रूपांतरण की गति और स्मृति के उपयोग मैं इस परीक्षण से डाटासेट गिरा दिया।
Cellarray(doubles)->matrix:d->m: 0.865s
Cellarray(mixed)->structarray:c->sc: 0.268s
Cellarray(doubles)->structarray:d->sd: 0.430s
Cellarray(mixed)->struct of arrays:c->sac: 0.361s
Cellarray(doubles)->struct of arrays:d->sad: 0.887s
Name Size Bytes Class Attributes
c 100000x10 68000000 cell
d 100000x10 68000000 cell
m 100000x10 8000000 double
sac 1x1 38001240 struct
sad 1x1 8001240 struct
sc 100000x1 68000640 struct
sd 100000x1 68000640 struct
================== कोड: जांच # 1
%% cellarray
c = cell(100000,10);
c(:,[1,3,5,7,9]) = num2cell(zeros(100000,5));
c(:,[2,4,6,8,10]) = repmat({'asdf'}, 100000, 5);
cols = strcat('Var', strtrim(cellstr(num2str((1:10)'))))';
te = tic;
for iii=1:1000
x = c(1234,5);
end
te = toc(te);
fprintf('cellarray:%0.3fs\n', te);
%% dataset
ds = dataset({ c, cols{:} });
te = tic;
for iii=1:1000
x = ds(1234,5);
end
te = toc(te);
fprintf('dataset:%0.3fs\n', te);
%% structarray
s = cell2struct(c, cols, 2);
te = tic;
for iii=1:1000
x = s(1234).Var5;
end
te = toc(te);
fprintf('structarray:%0.3fs\n', te);
%% struct of arrays
for iii=1:numel(cols)
if iii/2==floor(iii/2) % even => string
sac.(cols{iii}) = c(:,iii);
else
sac.(cols{iii}) = cell2mat(c(:,iii));
end
end
te = tic;
for iii=1:1000
x = sac.Var5(1234);
end
te = toc(te);
fprintf('struct of array:%0.3fs\n', te);
============= ===== कोड: जांच # 2
%% cellarray
% c - cellarray containing mixed type
c = cell(100000,10);
c(:,[1,3,5,7,9]) = num2cell(zeros(100000,5));
c(:,[2,4,6,8,10]) = repmat({'asdf'}, 100000, 5);
cols = strcat('Var', strtrim(cellstr(num2str((1:10)'))))';
% c - cellarray containing doubles only
d = num2cell(zeros(100000, 10));
%% matrix
% doubles only
te = tic;
m = cell2mat(d);
te = toc(te);
fprintf('Cellarray(doubles)->matrix:d->m: %0.3fs\n', te);
%% structarray
% mixed
te = tic;
sc = cell2struct(c, cols, 2);
te = toc(te);
fprintf('Cellarray(mixed)->structarray:c->sc: %0.3fs\n', te);
% doubles
te = tic;
sd = cell2struct(d, cols, 2);
te = toc(te);
fprintf('Cellarray(doubles)->structarray:d->sd: %0.3fs\n', te);
%% struct of arrays
% mixed
te = tic;
for iii=1:numel(cols)
if iii/2==floor(iii/2) % even => string
sac.(cols{iii}) = c(:,iii);
else
sac.(cols{iii}) = cell2mat(c(:,iii));
end
end
te = toc(te);
fprintf('Cellarray(mixed)->struct of arrays:c->sac: %0.3fs\n', te);
% doubles
te = tic;
for iii=1:numel(cols)
sad.(cols{iii}) = cell2mat(d(:,iii));
end
te = toc(te);
fprintf('Cellarray(doubles)->struct of arrays:d->sad: %0.3fs\n', te);
%%
clear iii cols te;
whos
जबकि 'डेटासेट' वास्तव में धीमा है, आपका समय बहुत धीमा है। मैं डेटासेट प्राप्त कर रहा हूं: पहुंच पर 0.7 एस 'जबकि अन्य आपके जैसा ही क्रम में हैं। मैं 32-बिट WinXP – Amro