convert multiple .txt into .mat in same folder

I want to automatically convert multiple .txt files in a folder into .mat file in same folder . How can i do it programmatically?

2 Comments

That depends on the contents of your txt files. What kind of variable should the file be loaded to? Once you have a script that converts the file to variables, it should be almost trivial to put that in a loop and run that for each file.
Thank you for your suggestion..I can solve it now.

Sign in to comment.

 Accepted Answer

You need to load the text files first, by making a loop on the file names and using textscan (or dlmread) in the loop to load each file; then you concatenate the results in one single matrix, and to finish you use the 'save' function which will give you the .mat file you're after

3 Comments

thank you so much.could you please give me an example code?
You should read the documentation for the functions mentioned, and/or post an example file and what form you want the variables to be.
Thank you for your suggestion..I can solve it now.

Sign in to comment.

More Answers (1)

Could you just share how were you able to do that?

1 Comment

This is not an answer. Please post this as a comment on either answer or the question itself and then delete this answer.

Sign in to comment.

Categories

Asked:

on 23 Aug 2018

Commented:

Rik
on 24 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!