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

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

help with a simple error

Asked by John on 19 Feb 2012
Latest activity Edited by Matt J on 16 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. The file names are matrix1.txt, matrix2.txt.....matrix100.txt.

I'm trying to import them all using

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

but I'm getting an error

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

would anybody know why?

Sincere thanks

0 Comments

John

Tags

Products

No products are associated with this question.

1 Answer

Answer by Wayne King on 19 Feb 2012

Are these files matrix1.txt, matrix2.txt, etc. located in a folder which is on the MATLAB path?

Use addpath, or pathtool, to add that folder to the MATLAB search path.

3 Comments

John on 19 Feb 2012

Hello,

Yes these files are in the current folder.

Do you mean this?

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

Could you suggest another way of importing them?

Regards

John

Wayne King on 19 Feb 2012

Hi John, are these just numeric matrices with no text in them?

are you sure that matrix1.txt all the way to matrix100.txt exists in that folder

John on 19 Feb 2012

Hi Wayne

Oh my fault, I didn't have exactly 100 files in the folder.

Thank you for spotting that!

John

Wayne King

Contact us