Comparision of two strings

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

Answers (2)

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

yes . This is my code
for i=1:457
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');
if strcmp(PATH~=N4)
V=hdr_read_volume(PATH);
end
end
Thanks for your advise. I am getting warning message. May I know the reason please?
Warning: Control
Character '\O' is not
valid.

Sign in to comment.

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

Here is my detailed question, I have 457 folders named OAS1_0001_MR1,OAS1_0002_MR1 etc. Each folder contains a file named OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc. In some folders OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc is replaced as OAS1_0001_MR1_mpr_n3_anon_111_t88_masked_gfc. I want to reject this n3 file and have to read n4 files. How do I solve this issue. I tried the following :
for i=1:457
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');
if strcmp(PATH~=N4)
V=hdr_read_volume(PATH);
end
end
Any help? Thanks in Advance
Try this:
% baseFileName is constant for all folders:
baseFileName = 'OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr';
for k = 1 : 457
thisFolder = sprintf('F:/OASIS/database/OAS1_%04d_MR1/PROCESSED/MPRAGE/T88_111', k);
fullFileName = fullfile(thisFolder, baseFileName);
if exist(fullFileName, 'file')
% Found the n4 file, so read it in:
V(k) = hdr_read_volume(fullFileName);
end
end
Thanks for your help. Here my baseFileName is not constant for all folders.It varies like OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr, OAS1_0002_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr,etc for 457 folders
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

Sign in to comment.

Categories

Find more on Communications Toolbox in Help Center and File Exchange

Products

Asked:

Jes
on 14 Jul 2015

Commented:

on 15 Jul 2015

Community Treasure Hunt

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

Start Hunting!