使用多个excel文件的表面图

时间:2018-06-14 14:27:21

标签: matlab plot graphics 3d

我只是MATLAB的初学者。

我需要使用3D绘图来表示我的数据。我尝试使用冲浪功能,但在我的情况下,这有点棘手。从代码中你会看到我循环遍历多个excel文件以从中提取数据。 使用三维图我需要将我的Fv阵列表示为' X'协调,我的FTsiga作为' Y'坐标和第三个坐标应该是我循环的每个excel文件。 (Fv,FTsiga)的情节看起来像附在此的图。 Fv(x-axis) , FTsiga(y-axis)

到目前为止,我编写的代码似乎无法执行,因为MATLAB由于内存不足或因为卡在循环中而崩溃。后者更有可能我猜。

    % Matlab trial code: Trying to loop through excel files strored in directory

source_dir = 'C:\UTwente\Q4\Structural Health and Condition monitoring\Case Roadbridge (Zwartewaterbrug)\Excel data'
source_files = dir(fullfile(source_dir, '*xlsx'));
len = length(source_files);
matrix = zeros(len,32);

X = zeros(len,32); Y = zeros(len,32); Z = zeros(len,32);
%looping through excel file in directory
for i=1:len
    data= xlsread(source_files(i).name,'Measurement data');
    for j=1:32
        sig = data(:,j);
        sig = sig - mean(sig);                                      % Remove d-c Offset
        L = length(sig);
        Fs = 1000;                                                  % Sampling Frequency
        Fn = Fs/2;                                                  % Nyquist Frequency
        FTsig = fft(sig)/L;
        Fv = linspace(0, 1, fix(length(FTsig)/2)+1)*Fn;             % Frequency Vector
        Iv = 1:length(Fv);                                          % Index Vector
        FTsiga = double(abs(FTsig(Iv))*2);                          % Truncate, Magnitude, Convert To Double
        sgf_sm = sgolayfilt(FTsiga, 5, 501);                        % Create ‘sgolayfilt’ Filtered FFT
        [~, idx] = max( sgf_sm );                                   % Getting the value of the modal frequency
        peakfreq = Fv( idx );
        matrix(i,j) = peakfreq;                                     % Matrix of all peak frequencies
        [X,Y,Z] = meshgrid(Fv,FTsiga,i);
    end
    surf(Fv,FTsiga,i);
end

0 个答案:

没有答案