我想剪掉signal.bin的一部分,然后将它(signal.bin的一部分)保存在w1.bin中
我用这些评论
f=fopen('signal.bin','rb');
v=fread(f,'float');
w1=v(0.93e8:1.3e8);
figure;plot(w1)
我想在w1.bin中保存w1
t=fopen('w1.bin', 'w+');
fwrite(t,w1);
fclose(t);
我打开w1.bin并绘制它
x=fopen('w1.bin','rb');
z=fread(x,'float');
figure;plot(z);
但情节(w1)和情节(z)不相同。有什么问题?
你写它不是单一的,而是双重的。 Matlab会将任何fread
读取转换为64位浮点值(称为double
)。正如它在这里说的https://nl.mathworks.com/help/matlab/ref/fread.html
By default, numeric and character values are returned in class 'double' arrays.
您在matlab中读取了32位浮点值(称为single
)。
把它改成这个可能:
f=fopen('signal.bin','rb');
v=fread(f,'*single'); %keep it single
fclose(f);
pntrs = uint64([0.93e8,1.3e8]); %don't use floating point values as pointers
w1=v(pntrs(1):pntrs(2));
t=fopen('w1.bin', 'w+');
fwrite(t,w1);
fclose(t);