Error when load file .dat in matlab - matlab

I have problem when I try to load file .dat in Matlab.
My file .dat about speech data:
% Read data file "orig.dat" with sampling rate of 8 kHz
% create an example sound
fs=8000;
t=0:1/fs:3;
x = 1*sin(2*pi*4*t)+0.25* sin(2*pi*560*t);
% play it back
%sound(x, 8000);
wavwrite(x,fs,16,'test56.wav');
y=wavread('test56.wav')
save y.dat y
load y.dat
There is a error:
??? Error using ==> load Number of columns on line 1 of ASCII file C:\Program Files\MATLAB\R2010b\bin\doan\y.dat
must be the same as previous lines.
Error in ==> twosubband at 8 load y.dat; % Load speech data
I don't understand.
Help me fix it.

load expects a file in its own data format. Try saving y as y.mat instead of y.dat.
That is, replace y.dat in both the line where you save and the line where you load by y.mat.
That should do the trick.

Related

MATLAB : Reading Data from a Updating file

I wrote a code for reading from a .txt file and putting it in the code below. When used without a loop or when looped once, it works fine. But I loop infinitely or over a certain constraint,it gives the error
Error using dlmread (line 147)
Empty format character vector is not supported at the end of a file.
My .txt contains 3 values separated by spaces.
How do I debug this error?
while 1
A =dlmread("Data.txt");
c130(30,10,0,...
'color','red',...
'pitch',A(1),...
'yaw',A(2),...
'roll',A(3),...
'scale',2)
view([42 8])
axis tight
end

MATLAB won't open a file created by Octave

I generated and saved large number of data files using Octave, and now I need to open them in MATLAB as part of analyzing them. MATLAB spits out this error.
Error using load
Unable to read MAT-file
[file path]/PhPar_40.mat: not a binary MAT-file.
Try LOAD -ASCII to read as text.
Trying its suggestion of load -ASCII then gives this error.
Error using load
Number of columns on line 2 of ASCII file
[filepath]/PhPar_40.mat must be the same as previous lines.
I (now) understand that Octave is capable of saving in a MATLAB readable format, but re-creating these data files would take an inordinate amount of time and really isn't an option. Is there a way to get MATLAB to read these files?
MATLAB can't open these files because these are not saved by octave properly. Try saving them in octave by following command:
save -mat7-binary '[filepath]/PhPar_40.mat' 'm'
If you have large number of files, you can place all files in folder and then run an iterator to read all load and save in correct format automatically. This iterator will look like:
file = dir('[filepath_read]/*.mat');
index = 1;
while (index==length(file)+1)
m = load('file(index).name')
save -mat7-binary strcat("[filepath_write]/", file(index).name, ".mat") 'm';
index = index+1;
pause(1);
endwhile
Once you have all the files converted to right format, load them in MATLAB. I hope it will solve your problem

Can't Visualize Ascii File on Matlab

I have .txt file created by an STM32 connected to a accelerometer sensors.
This file are Ascii file (probabily 8bit)
I tried to visualize on Matlab using
ZZ = load('000_LOG.TXT', '-ascii')
Error using load
Unknown text on line number 1 of ASCII file 000_LOG.TXT
so i tried
zx = load ('000_LOG.TXT')
Error using load
Unknown text on line number 1 of ASCII file 000_LOG.TXT
so i tried after reading this post importing ASCII file to Matlab
fid = fopen ('000_LOG.TXT');
>> myData = fread ('fid')
Error using fread
Invalid file identifier. Use fopen to generate a
valid file identifier.
The command "importdata" worked, but i can't convert to dec
Xw = importdata ('000_LOG.TXT')
Xw =
'|}}|}}|~}|~}|~}|}~|}~}}~}}~}}}}}~}}~}}|}}}}|}|}}~}}}}}}}|€}|}|€}}€}|...'
In fact
Wx = bin2dec(Xw)
Error using bin2dec (line 35)
Binary string must be 52 bits or less.
This is the link to the file .txt on dropbox
https://www.dropbox.com/l/s/mDoDk5puIpZaEdLth4w0Lr
Thanks for your support

No data written to file in Matlab when using writeVideo (Ubuntu)

I am attempting to create a movie file from ascii data using Matlab. I am running Matlab on Ubuntu 13.10. When I run my Matlab script (see below), the frames display correctly and the .avi video file is created at the end, but there is no data in the file.
clc
clear all
writerObj=VideoWriter('testVideo');
writerObj.FrameRate = 10;
open(writerObj);
for i=1:15000
j=i*100;
str=[num2str(j),'_Temp1.dat'];
t=importdata(str);
showaxes;
colorbar;
imagesc(t);
set(gca,'ydir','normal')
frame=getframe;
writeVideo(writerObj,frame);
% movieFrames(:,i) = frame;
end
close(writerObj);
And in Matlab I get the error:
Warning: No video frames were written to this file.
The file may be invalid.
> In VideoWriter.VideoWriter>VideoWriter.close at 307
In VideoWriter.VideoWriter>VideoWriter.delete at 256
In videomaker at 2
Error using importdata (line 136)
Unable to open file.
Error in videomaker (line 11)
t=importdata(str);

loading multiple .mat files in MATLAB

I have 110 files named time1.mat, time2.mat ..., time110.mat. I want to load these matrices into the MATLAB workspace.
I have always used load -'ASCII' matrix.mat to load an ASCII matrix file in the current folder.
So I tried doing
for i=1:10
filename=strcat('time',int2str(i),'.mat');
load -'ASCII' filename
end
But I am getting a MATLAB error as
??? Error using ==> load
Unable to read file filename: No such file or directory.
�
Of course the string filename seems to be evaluated correctly by MATLAB as time1.mat. in the first iteration where it crashes at the load line.
Any suggestions how I should do this?
Use load(filename, '-ascii')