MatLab GUI Load .mat File 導入mat文件


 

在MatLab中,我們用GUI時,有時候需要導入mat格式的圖片,但是在GUI中調用load和在命令行里調用load不一樣,在命令行里調用load('im.mat'),加載進去是uint8的矩陣,但是我們在GUI中寫代碼加進去,默認得到的是一個struct結構體,如果我們此時強行用imshow來顯示導入的數據,會出現如下錯誤:

??? Error using ==> iptcheckinput
Function IMAGEDISPLAYVALIDATEPARAMS expected its first input, I,
to be one of these types:

  double, single, uint8, uint16, uint32, int8, int16, int32, logical

Instead its type was struct.

 

為了取出其中的圖片數據,可浪費了我好幾個小時候,終於找到了方法,這樣我們就可以在GUI中的axes中顯示出圖片了,參見如下:

 

% Load im.mat
filename = uigetfile('*.mat');
img = cell2mat(struct2cell(load(filename)));
axes(handles.axes_1);
imshow(img);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM