Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Importing matrices in text files and creating a structure with 100 entries

Asked by John on 14 Feb 2012
Latest activity Edited by Matt J on 12 Oct 2013

Hello there,

I was hoping that somebody could perhaps help me out with a problem that I have. I'm only learning how to use matlab.

I have 100 4x4 matrices in .txt files in a folder.

How could I import them and create a structure with 100 entries and in each entry there would be one matrix.

The reason I ask is because I'm trying to get the average of these matrices and this post provides a solution if the matrices are in this format.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/292234

Thank you for your help

Regards

John

0 Comments

John

Products

No products are associated with this question.

1 Answer

Answer by Sean de Wolski on 14 Feb 2012

FAQ:How to process a sequence of files

Also note, that if they're all the same size, you could stack them along the third dimension and then take the mean of the first and second dimension which would leave you with each matrice's mean.

7 Comments

John on 15 Feb 2012

Thank you Sean

Sean de Wolski on 15 Feb 2012

You're welcome!

Were you able to get it working?

John on 15 Feb 2012

Hi again,

Honestly I haven't been able to get it to work

This is the code I'm using

C = cell(100,1);
for ii = 1:100
C{ii} = importdata(['matrix' num2str(ii) '.txt']) ;
end

but I'm getting this error

??? Error using ==> importdata at 123
Unable to open file.

The files are just text files each containing a 4x4 matrix

Could you offer any further suggestions?

Thank you

Sean de Wolski

Contact us