I have this function made to sort data into a structure. However, when I call a directory as the input, I can't seem to get an output. I call it by doing
filesort(dir([foldername(1).standard,'\*.dat'])).
However, when I set x=sortdata(dir([foldername(1).standard,'\*.dat'])), within the function and run it, I get my desired Srt structure.
Any ideas?
This is the function:
function []=filesort(x)C = {'Z1P'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z1P = S(idx);C = {'Z2P'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z2P = S(idx);C = {'Z1G'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z1G = S(idx);C = {'Z2G'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z2G = S(idx);C = {'Z3K'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z3K = S(idx);C = {'Z4K'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z4K = S(idx);C = {'Z5K'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z5K = S(idx);C = {'Z3M'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z3M = S(idx);C = {'Z4M'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z4M = S(idx);C = {'Z5M'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z5M = S(idx);C = {'Z6MS'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z6MS = S(idx);C = {'Z7PR'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z7PR = S(idx);C = {'Z7PR1'};S = x;fun = @(s)cellfun('isempty',regexp(s,C,'once'));idx = cellfun(@(s)any(~fun(s)),{x.name});Srt.Standard(1).Z7PR1 = S(idx);end
Best Answer