Comparision of two strings
4 views (last 30 days)
Show older comments
How to compare all the characters of the following two strings. I tried with strcmp, but it doesn't take the numbers for comparision. I have to differentiate n3 and n4 in the following lines
PATH=strcat('F:\OASIS\database\OAS1_',num2str(i,'%04d'),'_MR1\PROCESSED\MPRAGE\T88_111\OAS1_',num2str(i,'%04d'),'_MR1_mpr_n4_anon_111_t88_masked_gfc','.hdr');
N4=strcat('F:\OASIS\database\OAS1_',num2str(i,'%04d'),'_MR1\PROCESSED\MPRAGE\T88_111\OAS1_',num2str(i,'%04d'),'_MR1_mpr_n3_anon_111_t88_masked_gfc','.hdr');
Any help? Thanks in Advance
0 Comments
Answers (2)
the cyclist
on 14 Jul 2015
I don't understand what you are trying to do. Did you define a value for i before you ran this code? I ran
i = 3;
PATH=strcat('F:\OASIS\database\OAS1_',num2str(i,'%04d'),'_MR1\PROCESSED\MPRAGE\T88_111\OAS1_',num2str(i,'%04d'),'_MR1_mpr_n4_anon_111_t88_masked_gfc','.hdr');
N4=strcat('F:\OASIS\database\OAS1_',num2str(i,'%04d'),'_MR1\PROCESSED\MPRAGE\T88_111\OAS1_',num2str(i,'%04d'),'_MR1_mpr_n3_anon_111_t88_masked_gfc','.hdr');
strcmp(PATH,N4)
which ran to completion with no error.
2 Comments
Image Analyst
on 14 Jul 2015
Try this
differentIndexes = find(PATH ~= N4);
By the way, have you ever thought about using sprintf() for a much simpler way to build strings?
4 Comments
Image Analyst
on 15 Jul 2015
Then just create the filename and search for n4 within it.
if ~isempty(fullFileName, '_n4_')
% Found the n4 file, so read it in:
V(k) = hdr_read_volume(fullFileName);
end
See Also
Categories
Find more on Get Started with MATLAB in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!