How to load .txt files into MATLAB from server?

3 vues (au cours des 30 derniers jours)
Austin Jandreau
Austin Jandreau le 14 Fév 2020
Commenté : Geoff Hayes le 18 Fév 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)

Réponses (1)

Geoff Hayes
Geoff Hayes le 14 Fév 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 commentaires
Austin Jandreau
Austin Jandreau le 18 Fév 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 le 18 Fév 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?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Environment and Settings dans Help Center et File Exchange

Tags

Produits


Version

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by