我试图使用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对象,而out尝试将其转换为JSON,如下所示。在
^{pr2}$我无法理解它的意义。我不知道。我只能从MATLAB运行这个脚本,它又胖又笨,而且很快乐。在
这里有Python和MATLAB代码。在
^{3}$以及没有绘图的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
函数来计算信号的短时傅里叶变换,然后创建绘图(请参见documentation)。在计算转换后:
至少有两种方法可以创建谱图图:
^{pr2}$surf
,这是spectrogram
和imagesc
隐式使用的图。在第一种情况下,可以使用以下代码显示绘图(请参阅documentation):使用
imagesc
(参考this上一个答案和this注释):相关问题 更多 >
编程相关推荐