Need help on matlab table

1 回表示 (過去 30 日間)
Tanu Shree
Tanu Shree 2020 年 10 月 2 日
回答済み: per isakson 2020 年 10 月 3 日
I have a text file with object name like 'ABC_01.REST.BKP.Blr.RR.nii' and classifier. I want to loop through each object name based on the classifier but dot in file name is creating a problem, Any idea how to handle this?
ABV_0016.REST.blr6.dtAROMA_MNI.nii Controlled
ABV_0017.REST.blr6.dtAROMA_MNI.nii Syndrome 1
ABV_0019.REST.blr6.dtAROMA_MNI.nii Syndrome 2
ABV_0022.REST.blr6.dtAROMA_MNI.nii Syndrome 2
ABV_0030.REST.blr6.dtAROMA_MNI.nii Controlled
  3 件のコメント
Tanu Shree
Tanu Shree 2020 年 10 月 2 日
My input will be classifier name like in above mentioned case Let's say If I pass Controlled it should give me two file name ABV_0016.REST.blr6.dtAROMA_MNI.nii and ABV_0030.REST.blr6.dtAROMA_MNI.nii.
Rik
Rik 2020 年 10 月 2 日
You misunderstood me. The text you posted is not valid Matlab syntax, so what is your exact data?

サインインしてコメントする。

採用された回答

per isakson
per isakson 2020 年 10 月 3 日
Assumption: You have a text file that contains exactly the five lines of text formatted as code in your question.
Run the function cssm as in this example
>> object_names = cssm( 'd:\m\cssm\cssm.txt', 'Controlled' )
object_names =
2×1 cell array
{'ABV_0016.REST.blr6.dtAROMA_MNI.nii'}
{'ABV_0030.REST.blr6.dtAROMA_MNI.nii'}
>>
>> object_names = cssm( 'd:\m\cssm\cssm.txt', 'Syndrome 2' )
object_names =
2×1 cell array
{'ABV_0019.REST.blr6.dtAROMA_MNI.nii'}
{'ABV_0022.REST.blr6.dtAROMA_MNI.nii'}
>>
where
function object_names = cssm( ffs, classifier )
fid = fopen( ffs, 'rt' );
cac = textscan( fid, '%s%[^\n]', 'CollectOutput',true );
[~] = fclose( fid );
cac = strtrim( cac{1} );
is_selected = strcmp( cac(:,2), classifier );
object_names = cac( is_selected, 1 );
end
Comments:
  • It's possible to use a loop, but I see no reason to do that.
  • How does the dot in the file name create a problem?
  • The space in some classifier values requires a special solution. In the function, cssm, I read the first "word" (i.e. the object name) and then the rest of the row to the second column.
  • There are other solutions, e.g. using readtable()

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeText Data Preparation についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by