Select max files in a struct
显示 更早的评论
I have 30 patients who underwent a brain scan.
Each patient has a directory that is named "CANDOWN" with a unique ID at the end.
Within each patient directory, there are a further 3 directories. Two of these directories are numbered. These are of interest. One direcotry is named "DICOM" which I am not inerested in.
I want my Matlab script to automatically detect the max and min directories, and then select all of the files within the directories respectively. For ease I will focus only on the max directory.
--------------
I ran this code:
--------------
name=2;
allT1=[];
T1 = dir(['/data/project/CANDOWN/bg/CANDOWN00',num2str(name),'A']) %A is because half my patients took a drug. The other half a placebo. A= drug. B= placebo
dirT1 = max(allT1)
--------------
These are my results:
--------------
T1 =
5x1 struct array with fields:
name
date
bytes
isdir
datenum
dirT1 =
[]
----------
This is not correct however, as the answer should be 0011
---------
When I put "T1.name" in the command window, I see the correct directories. When I try max (T1.name) for instance, I get the error
Error using max
Too many input arguments.
---------
I have read elsewhere that my issue is that I can not max and min a struct? It must be an index?
Any suggestions would be useful.
Many thanks,
Brandon
3 个评论
Walter Roberson
2020-7-21
Are you trying to extract the number from the file names and max those?
You appear to be using leading zeros on the numbers. In such a case, sort() of the file names also ends up sorting the numbers.
Brandon Gunasekera
2020-7-21
Walter Roberson
2020-7-22
max(str2double(regexp({T1.name}, '\d+', 'match')))
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!