首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python MATLAB桥JSON错误

Python MATLAB桥JSON错误
EN

Stack Overflow用户
提问于 2014-07-29 05:17:56
回答 1查看 195关注 0票数 1

我正在尝试使用Python- to -MATLAB桥,我不知道这是怎么回事。

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

代码语言:javascript
复制
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将其放入,如下所示。

代码语言:javascript
复制
<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代码。

代码语言:javascript
复制
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代码:

代码语言:javascript
复制
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

现在开始绘图了。

代码语言:javascript
复制
    %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);
EN

回答 1

Stack Overflow用户

发布于 2014-07-29 16:19:09

我怀疑这个问题与spectrogram函数创建的图形有关。通过指定输出,您可以使用spectrogram函数计算信号的短时傅立叶变换,然后创建曲线图(请参阅documentation)。

计算完变换后:

代码语言:javascript
复制
[S,F,T] = spectrogram(x,window,noverlap,F,fs)

至少有两种方法可以创建频谱图:surf,这是spectrogramimagesc隐式使用的方法。在第一种情况下,您可以使用以下代码显示绘图(请参阅documentation):

代码语言:javascript
复制
surf(T, F, 10*log10(abs(P)));
axis tight;
view(0, 90);

使用imagesc (请参阅this上一个答案和this注释):

代码语言:javascript
复制
%plot the log spectrum
imagesc(T, F, log(S));

%flip the Y Axis so lower frequencies are at the bottom
set(gca, 'YDir', 'normal');
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25004515

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档