Hi,
I have had a try at getting a string ending with a space to be preserved on screen using fprintf and strcat together but cannot preserve the spaces.
B=strcat(PR1,'.mat');filey=B% Y='.*2'
% if ~isempty(regexp(directory,Y))
% end
% *****************************
%%THIS PRODUCES A LIST OF ONLY THE MAT FILES
d=dir;% d1=cellstr(d)
d1=struct2cell(d); d2=d1(1,:); d3=cellfun(@(x) regexp(x,'.mat'),d2,'uni',false); d4=find(~cellfun('isempty', d3)); theMATfiles=d2(d4)' natsort(theMATfiles)%download natsort function from file exchange
% pwd
k=1;% for k = 1:20
% Create a mat filename, and load it into a structure called matData.
matFileName = sprintf('mat%d.mat',k);% save(matFileName)
% load('matData.mat')
if exist(B, 'file') A = load(filey); fprintf(strcat('HURRAH!! File',{''},B,' does exist.\n')); else % fprintf('File %s does not exist.\n', matFileName);
fprintf(strcat('NOPE!! File','_',B,' does not exist.\n')); end
I have tried placing a space e.g. {''} but it did not work, I get the following error:
Error using fprintfInvalid file identifier. Use fopen to generate a valid file identifier.Error in mat_ides_03 (line 53) fprintf(strcat('HURRAH!! File',{''},B,' does exist.\n'));
Best Answer