mercredi 24 mai 2017

Issue Loading .txt Files with Elseif Loops in Matlab

I have been struggling to write the code to read in .txt data. I am in a directory where all of the file names are ‘img0001.txt’ through ‘img4200.txt’. Each file is a 2-D array of the same size (480x640), eventually I want to fill a 3-D data cube, but first I need to be able to read in all the data.

for i = 1:4200

    i

    if i<10
        A = csvread(['img000',num2str(i),'.txt']);

    elseif 10<=i<100
        A = csvread(['img00',num2str(i),'.txt']); ***

    elseif 100<=i<1000
        A = csvread(['img0',num2str(i),'.txt']);

    else i>=1000
        A = csvread(['img',num2str(i),'.txt']);

    end
end

The code prints i=100, and then gives me an error message for a file not found in the line where I added ***. The code is looking for file ‘img00100.txt’ which does not exist, but I’m not sure why it is doing this.

I have been playing with different versions of writing the if, elseif, statements and the greater than and less than operators. I have also tried using eval and load commands.

Thank you.

Aucun commentaire:

Enregistrer un commentaire