Python MATLAB bridge JSON error



我正在尝试使用python到matlab桥接,我不知道发生了什么。

每次我运行我的脚本,我得到这个错误:

File "/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/test.py", line 8, in <module>
res = mlab.run('/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/jk.m', {'arg1': 3, 'arg2': 5, 'arg3': 4}, maxtime=20)
  File "/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/pymatbridge/__init__.py", line 85, in run
result = self._open_page(self.eval_func, page_args, maxtime)
   File "/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/pymatbridge/__init__.py", line 96, in _open_page
return json.loads(page.read())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/json/decoder.py", line 385, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

然后我试着做GitHub页面前面给出的基本的一个。这工作。我慢慢地从另一个MATLAB脚本中复制和粘贴代码,直到我得到了我制作绘图的地方,一旦我这样做了,我就不能再运行它了。它就是不这样做,总是给我同样的错误,即使我删除了绘图代码。

我进入并打印出有问题的JSON对象,没有尝试将其通过JSON进行处理,结果如下:

<html><body><font color="#FF0000">Error in file : web_feval.m</font><br><br><font color="#990000"> The file returned the following error: <br>Printing of uicontrols is not supported on this platform.</font></body></html> 0

我不知道它要去哪里。我不知道。我只能从MATLAB中运行这个脚本,它很胖,很笨,很开心。

为了更好地测量,这里是Python和MATLAB代码。

from pymatbridge import Matlab
import os
mlab = Matlab(matlab='/Applications/MATLAB_R2014a.app/bin/matlab')
matlabStart = mlab.start()
if not os.path.isfile('/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/plot_maker.m'):
    print 'well here is your issue'
res = mlab.run('/Users/Casey/Desktop/ABOVE_TCP/Ingestion_software/jk.m', {'arg1': 3, 'arg2': 5, 'arg3': 4}, maxtime=20)
print res['result']
mlab.stop()

和没有绘图的MATLAB代码:

function lol = jk(args)
    restoredefaultpath;
    clc;
    clear all;
    close all;
    clear functions;
    bdclose('all');
    fclose('all');
    arg1 = args.arg1
    arg2 = args.arg2
    arg3 = args.arg3
    fileName = '/Users/Casey/Desktop/MatlabTest/20140714_175009_cmrs_above_Full_Data.dat';
    summaryFileName =     '/Users/Casey/Desktop/MatlabTest/20140714_175009_cmrs_above_summary_plot.png';
    windowSize = 2048;
    overLap = windowSize * 0.75;
    sampleFreq = 150000;
    Window = hann(windowSize);
    dataFile = fopen(fileName);
    header = blanks(115);
    i = 1;
    %dataContents = fileread(fileName);
    dataContents = fread(dataFile);
    while i < 115
        char = dataContents(i);
        header(i) = char;
        if char == '}'
            break
        end
        i = i + 1;
    end
    header = header(2:i-1);
    headerSplit = strsplit(header,',');
    fileSize = str2double(headerSplit(17));
    fseek(dataFile, i + 0,'bof');
    Info = dir(fileName);
    Data = fread(dataFile,[Info.bytes 1], 'bit16', 0, 'b'); % Need to muliply filesize by 2 for final release
    fseek(dataFile, Info.bytes-10, 'bof');
    %Decide if end key check is needed, and what to do with it
    %endKey = textscan(dataFile, '%s');
    %endKey = endKey{1}{1};
    fclose(dataFile);
    Data = Data(1:fileSize/2);
    Chan1 = Data(1:2:end);
    Chan2 = Data(2:2:end);
    FFTChan1 = fft(Chan1, sampleFreq);
    FFTChan2 = fft(Chan2, sampleFreq);
    %iniliaze vectors for the polarizations
    LHC = zeros(length(FFTChan1),1);
    RHC = zeros(length(FFTChan1),1);
    TP = zeros(length(FFTChan1),1);

    for i = 1:length(FFTChan1)
        TP(i) = abs(FFTChan1(i))+abs(FFTChan2(i));
        RHC(i) = real(FFTChan1(i))+imag(FFTChan2(i));
        LHC(i) =real(FFTChan1(i))-imag(FFTChan2(i));
    end
    TPS = ifft(TP);
    RHCS = ifft(RHC);
    LHCS = ifft(LHC);
    maxTime = (length(Chan1)-1)/sampleFreq;

    lol = 'YYYUUUUUPPPPP';
    %lol = arg1 + arg2 + arg3;
end

现在开始绘图。

    %start making the plots!
    %set(gcf, 'Visible', 'off');
    %subplot(3,1,1);
    %spectrogram(TPS, Window, overLap,windowSize, sampleFreq, 'yaxis');
    %colorbar;
    %axis([0 maxTime 0 75000]);
    %title('Total Power');
    %subplot(3,1,2);
    %spectrogram(LHCS, Window, overLap,windowSize, sampleFreq, 'yaxis');
    %colorbar;
    %axis([0 maxTime 0 75000]);
    %title('Left Hand Cicular Polarization');
    %subplot(3,1,3);
    %spectrogram(RHCS, Window, overLap, windowSize, sampleFreq, 'yaxis')
    %colorbar;
    %axis([0 maxTime 0 75000]);
    %title('Right Hand Ciruclar Polarization');
    %saveas(1,summaryFileName);

我怀疑这个问题与spectrogram函数创建的图形有关。通过指定输出,您可以使用spectrogram函数来计算信号的短时傅里叶变换,然后创建绘图(参见文档)。

计算变换后:

[S,F,T] = spectrogram(x,window,noverlap,F,fs)

您至少有两种选择来创建谱图:surf,这是spectrogramimagesc隐式使用的一个。在第一种情况下,您可以使用以下代码显示绘图(参考文档):

surf(T, F, 10*log10(abs(P)));
axis tight;
view(0, 90);

使用imagesc(参考前面的回答和这个评论):

%plot the log spectrum
imagesc(T, F, log(S));
%flip the Y Axis so lower frequencies are at the bottom
set(gca, 'YDir', 'normal');

最新更新