How to save a text file to a .mat file?
up vote
-1
down vote
favorite
How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.
My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.
Appreciate any help is appreciated. Thanks in advance.
python-2.7 matlab text-files mat-file
add a comment |
up vote
-1
down vote
favorite
How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.
My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.
Appreciate any help is appreciated. Thanks in advance.
python-2.7 matlab text-files mat-file
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.
My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.
Appreciate any help is appreciated. Thanks in advance.
python-2.7 matlab text-files mat-file
How do I save a '.txt' file as a '.mat' file, using either MATLAB or Python?
I tried using textscan() (in MATLAB), and scipy.io.savemat() (in Python). Both didn't help.
My text file is of the format: value1,value2,value3,valu4 (each row) and has over 1000 rows.
Appreciate any help is appreciated. Thanks in advance.
python-2.7 matlab text-files mat-file
python-2.7 matlab text-files mat-file
asked 2 days ago
aiEvangelist
86
86
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
3
down vote
You can use textscan
to read the file and save
to save the variables into a .mat file
fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');
This works because your file seems to have a fixed format.
Have a look at this and this
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell inC
.
– user7431005
yesterday
add a comment |
up vote
0
down vote
I was able to get it to work using csvread() as follows:
file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');
add a comment |
up vote
-3
down vote
if what you need is to change file format:
mv example.mat example.txt
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
3
down vote
You can use textscan
to read the file and save
to save the variables into a .mat file
fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');
This works because your file seems to have a fixed format.
Have a look at this and this
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell inC
.
– user7431005
yesterday
add a comment |
up vote
3
down vote
You can use textscan
to read the file and save
to save the variables into a .mat file
fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');
This works because your file seems to have a fixed format.
Have a look at this and this
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell inC
.
– user7431005
yesterday
add a comment |
up vote
3
down vote
up vote
3
down vote
You can use textscan
to read the file and save
to save the variables into a .mat file
fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');
This works because your file seems to have a fixed format.
Have a look at this and this
You can use textscan
to read the file and save
to save the variables into a .mat file
fid = fopen('yourTextFile.txt');
C = textscan(fid,'%f %f %f %f');
fclose(fid);
% maybe change the cells from `C` to a single matrix
M = cell2mat(C);
save('myMatFile.mat','M');
This works because your file seems to have a fixed format.
Have a look at this and this
answered 2 days ago
user7431005
648114
648114
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell inC
.
– user7431005
yesterday
add a comment |
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell inC
.
– user7431005
yesterday
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
When I run this, I get the following error:Error using cat Dimensions of matrices being concatenated are not consistent. Error in cell2mat (line 75) m{n} = cat(2,c{n,:});
– aiEvangelist
2 days ago
Can you please give more information about the content of your file and the dimension of each cell in
C
.– user7431005
yesterday
Can you please give more information about the content of your file and the dimension of each cell in
C
.– user7431005
yesterday
add a comment |
up vote
0
down vote
I was able to get it to work using csvread() as follows:
file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');
add a comment |
up vote
0
down vote
I was able to get it to work using csvread() as follows:
file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');
add a comment |
up vote
0
down vote
up vote
0
down vote
I was able to get it to work using csvread() as follows:
file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');
I was able to get it to work using csvread() as follows:
file = csvread('yourTextFile.txt');
save('myMatFile.mat','file');
answered 23 hours ago
aiEvangelist
86
86
add a comment |
add a comment |
up vote
-3
down vote
if what you need is to change file format:
mv example.mat example.txt
add a comment |
up vote
-3
down vote
if what you need is to change file format:
mv example.mat example.txt
add a comment |
up vote
-3
down vote
up vote
-3
down vote
if what you need is to change file format:
mv example.mat example.txt
if what you need is to change file format:
mv example.mat example.txt
answered 2 days ago
liaofeng
596
596
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53203507%2fhow-to-save-a-text-file-to-a-mat-file%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password