在matlab中切片“使用griddedInterpolant的错误”

时间:2017-03-30 15:37:58

标签: matlab

我正在尝试绘制土壤体积数据的切片图,但我在尝试绘制切片时遇到此错误(大多数错误文本来自我的代码层次结构,因为我通过Gui执行代码但顶部是最重要的问题):

Error using griddedInterpolant
The grid vectors do not define a grid of points that match the given values.

Error in interp3 (line 142)
            F = griddedInterpolant(X, Y, Z, V, method,extrap);

Error in slice (line 100)
    vi = interp3(x,y,z,v,xi,yi,zi,method);

Error in ANALYSE>Bouton3D_Callback (line 939)
slice(x,y,z,VOLUME_DATA,xslice,yslice,zslice,'nearest')

Error in gui_mainfcn (line 95)
        feval(varargin{:});

Error in ANALYSE (line 42)
    gui_mainfcn(gui_State, varargin{:});

Error in @(hObject,eventdata)ANALYSE('Bouton3D_Callback',hObject,eventdata,guidata(hObject))


Error while evaluating UIControl Callback

这是我的代码有问题(它指向的行是最后一行):

function Bouton3D_Callback(hObject, eventdata, handles)
% hObject    handle to Bouton3D (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
NB_LIGNES =str2num(get(handles.nb_lignes,'string'));
NB_COLONNES = str2num(get(handles.nb_colonnes,'string'));
SENSIBILITE_AMPLITUDE_SIGNAL =1;

TEMP = dir('L1/f1.csv');
FICHIER_SIGNAL_SPECTRAL= ['L1/',TEMP.name];
TABLEAU_SIGNAL_SPECTRAL = xlsread(FICHIER_SIGNAL_SPECTRAL);
NB_FREQ = size(TABLEAU_SIGNAL_SPECTRAL,1);

FREQUENCES = TABLEAU_SIGNAL_SPECTRAL(:,2);

VOLUME_DATA = zeros(NB_LIGNES,NB_COLONNES,NB_FREQ);



for L =1:NB_LIGNES
    for C =1:NB_COLONNES
        TEMP = dir(['L',num2str(L),'/f',num2str(C),'.csv']);
        FICHIER_SIGNAL_SPECTRAL= ['L',num2str(L),'/',TEMP.name];

        TABLEAU_SIGNAL_SPECTRAL = xlsread(FICHIER_SIGNAL_SPECTRAL);

        VOLUME_DATA(L,C,:)=(TABLEAU_SIGNAL_SPECTRAL(:,3)*SENSIBILITE_AMPLITUDE_SIGNAL); % En dB

    end
end

[x,y,z] = meshgrid(1:5,1:9,FREQUENCES);
xslice = 1; 
yslice = 1; 
zslice = 1:FREQUENCES(end)/5:FREQUENCES(end)-1;
slice(x,y,z,VOLUME_DATA,xslice,yslice,zslice,'nearest')
colormap hsv

1 个答案:

答案 0 :(得分:1)

我尝试了您的代码,在我看来VOLUME_DATA的大小不正确。如果我稍微修改你的代码,它不会抛出任何错误:

FREQUENCES = 1:6;
[x,y,z] = meshgrid(1:5,1:9,FREQUENCES);
VOLUME_DATA = x.*exp(-x.^2-y.^2-z.^2); % a function of x,y,z such that the output dimension fits the inputs dimensions 
xslice = 1;
yslice = 1;
zslice = 1:FREQUENCES(end)/5:FREQUENCES(end)-1;
slice(x,y,z,VOLUME_DATA,xslice,yslice,zslice,'nearest')
colormap hsv

或者尝试:

[x,y,z] = meshgrid(1:size(VOLUME_DATA,1),1:size(VOLUME_DATA,2),FREQUENCES);