function sdirs = get_subfolders(indir)
dirstruc = dir(indir);
dirstruc = dirstruc([dirstruc.isdir]); % no files, only folders
dirstruc = dirstruc(~ismember({dirstruc.name},{'.','..'})); % remove dot folders
sdirs = {dirstruc.name};
end
Hashtables (key-value pairs)
Table structure as of MATLAB 2013b.
iconsec = diff(aVec)==1;
iconsec = [true iconsec]; % diff is length-1 (diff of pairs), so add 1st elem back
ijumps = find(iconsec==0);
iic = 1;
for ii=1:length(ijumps)
strSub = sprintf('[%03d-%03d,',aVec(iic),aVec(ijumps(ii)-1));
iic = ijumps(ii);
end
% grab the last few
if ijumps < length(aVec)
strSub = sprintf('%03d-%03d]',strSub,aVec(end),aVec(end));
end
Table variables of strings (type character) are like character arrays and must have the same length -- trying to add rows to the table when this is not the case will trigger the VERTCAT error:
Error using vertcat
Dimensions of arrays being concatenated are not consistent.
A workaround is to cast the table variable as a cell string cellstr() or string type string(), e.g.
newrow.ID = string(theID);
someDataTbl = [someDataTbl; newrow];
Access the cell with ( ) and set that cell to []. Notice that if you accessed the cell with { }, the cell will not be deleted but set to an empty cell.
Example:
>> x= {'sub1';'sub2';'sub3'}
x =
3x1 cell array
{'sub1'}
{'sub2'}
{'sub3'}
>> x(1)
ans =
1x1 cell array
{'sub1'}
>> x{1}
ans =
'sub1'
>> x(1) = []
x =
2x1 cell array
{'sub2'}
{'sub3'}
>> x{2} = []
x =
2x1 cell array
{'sub2' }
{0x0 double}