簡體   English   中英

使用MATLAB腳本加載Mat文件錯誤

[英]Loading mat file error using MATLAB script

我已經下載了一個腳本,該腳本顯示了使用gui過濾后的投影示例。 該程序包工作正常,但是當我加載一個墊子時,腳本無法識別它,並說“這不是MAT文件!”。 在這里,我從腳本中復制了幾行。 值得一提的是該腳本是在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

有什么建議么 ?

upper將字符串轉換為大寫,因此至少需要:

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

但是在MATLAB中有字符串比較函數,所以我改用這樣的東西:

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

strcmpi比較兩個字符串是否相等,忽略字母大小寫的任何差異。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM