Turki
Turki

Reputation: 71

Loading mat file error using MATLAB script

I have downloaded a script that shows a filtered back projection example using gui. The package works fine but when I load a mat, the script doesn't recognise it and says 'That was NOT a MAT file!'. Here I copied some lines from the script. It might worth mentioning that the script was written in 2009.

function open_Callback(h, eventdata)
    [file_name, mach_path] = uigetfile( ...
      {'*.mat', 'All MAT-Files (*.mat)'}, ... 
      'Select File');

    % If "Cancel" is selected then return
    if isequal([file_name,mach_path],[0,0])
      return   
      % Otherwise construct the fullfilename and Check and load the file
    end

    filename=file_name;
    length_fn=length(filename);
    st_pt=length_fn+1-4;
    file_ext=filename(st_pt:length_fn);

    if upper(file_ext) == '.mat' % if the file is a mat file
      data = load(file_name);
      figure
      imagesc(data.sinogram), colormap(hot)
      title(data.txt)
    else
      msgbox('That was NOT a MAT file!','ERROR','error','modal')
      disp('That was NOT a MAT file!')
    end
  end

Any suggestions ?

Upvotes: 1

Views: 60

Answers (1)

am304
am304

Reputation: 13886

upper converts the string to upper case, so at the very least you need:

if upper(file_ext) == '.MAT' % if the file is a mat file

but there string comparison functions in MATLAB so I would use something like this instead:

 if strcmpi(file_ext,'.mat') % if the file is a MAT file

strcmpi compares two strings for equality, ignoring any differences in letter case.

Upvotes: 2

Related Questions