Function to load a .mat file (which can be inside or outside matlab folder) and perform analysis for finding constant or near-zero variance values
1 次查看(过去 30 天)
显示 更早的评论
I have a matlab data file that has only one variable of type 1x1 struct which has 1x680 cell which has 680 MxN double values (values can be -ve, 0 or +ve). I want to load this data file using a function and find constant and near-zero variance values in this data set.
Thanks in advance.
0 个评论
采纳的回答
Walter Roberson
2018-2-4
[filename, pathname] = uigetfile('*.mat', 'Selected mat file');
if isnumeric(filename); return; end %user cancel
filename = fullfile(pathname, filename);
datastruct = load(filename);
varnames = fieldnames(datastruct);
datacell = datastruct.(varnames{1}); %there should only _be_ one, but just in case there are more
variances = cellfun(@(M) var(M(:)), datacell);
has_small_variance = abs(variances) < 1e-5;
selected_cells = datacell(has_small_variance);
7 个评论
Walter Roberson
2018-2-7
tol = input('What tolerance do you want?');
means = cellfun(@mean2, datacell);
variances = cellfun(@(M) var(M(:)), datacell);
has_small_variance = abs(variances) < tol;
selected_cells = datacell(has_small_variance);
selected_variances = variances(has_small_variance);
selected_means = means(has_small_variance);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 String Parsing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!