Info
此问题已关闭。 请重新打开它进行编辑或回答。
How to state a while condition to prevent an action?
1 次查看(过去 30 天)
显示 更早的评论
Hi I have a code that adds the .dcm extension to files they don't have .dcm extension. The problem is that whenever I run the script, it keeps adding .dcm extension forever and ever. For instance a file named S009 can be like S009.dcm.dcm.dcm if I run the script three times. I need a close a while statement to check if the file has .dcm extension and if true to leave it as it is.
Any idea?
Thanks in advance
0 个评论
回答(1 个)
Star Strider
2018-4-29
You can test for the presence of the ‘.dcm’ extension easily enough:
has_dcm = ~isempty(strfind(filename, '.dcm')); % Statement
has_dcm = @(fname) ~isempty(strfind(fname, '.dcm')); % Anonymous Function
This will return ‘true’ (logical 1) if it already has a ‘.dcm’ extension and 0 if it does not. You can use it to test for the presence of the extension, then add it if the result is 0 and branch around that if the result is 1.
5 个评论
Star Strider
2018-4-30
My solution worked when I tested it.
I would have to see the relevant parts of your code to see if I can understand what the problem is with it.
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!