How to load .txt files into MATLAB from server?

2 visualizaciones (últimos 30 días)
Austin Jandreau
Austin Jandreau el 14 de Feb. de 2020
Comentada: Geoff Hayes el 18 de Feb. de 2020
Hello All, I am currently having trouble geting the data in my .txt files to be displayed in MATLAB. I can see file names, but recieve errors when i run the full code. The maindir is just three random .txt files that have one line of text which says "test" and are saved in a folder on a server. All 3 files have different names(ex. test2.txt numerouno.txt,test3.txt) Any thoughts or suggestions would be greatly appreciated.
maindir=['U:\Random\text files for matlab code test'];
cd(maindir)
textfiles=dir('*.txt');
textfiles.name
numfiles=1:length(textfiles);
mydata=cell(1,numfiles);
for k=1:numfiles
mydata(k)=importdata(textfiles(k).name);
end
data=mydata(k);
disp(mydata)

Respuestas (1)

Geoff Hayes
Geoff Hayes el 14 de Feb. de 2020
Austin - what is the error that you are observing? Is it
Error using cell
Size inputs must be scalar.
Note the code
numfiles=1:length(textfiles);
mydata=cell(1,numfiles);
where numfiles is an array with elements 1 2 3 ... up to the number of text files. I think that you want to do
numfiles=length(textfiles);
mydata=cell(1,numfiles);
instead. Also, since mydata is a cell array, you may want to try indexing with {} braces instead of () brackets
mydata{k}=importdata(textfiles(k).name);
  2 comentarios
Austin Jandreau
Austin Jandreau el 18 de Feb. de 2020
Hello Geoff Hayes,
First up thank you for responding to my question, it is myuch appreciated.
Secondly, Yes the error ithat was seeing was the following:
Error using cell
Size inputs must be scalar.
I tried out the recommendations and recieved a new error. The new error being seen is:
??? Error using ==> text
Invalid parameter/value pair arguments
Im going to play around with the code for a bit and try a few changes to see if i can get it to work, any thoughts on the new error?
Geoff Hayes
Geoff Hayes el 18 de Feb. de 2020
Austin - I'd have to see the line of code that is generating the error message. Are you now calling the text function? Or doing something else?

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by