How to load .txt files into MATLAB from server?

3 次查看(过去 30 天)
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)

回答(1 个)

Geoff Hayes
Geoff Hayes 2020-2-14
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 个评论
Austin Jandreau
Austin Jandreau 2020-2-18
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 2020-2-18
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

标签

产品


版本

R2010a

Community Treasure Hunt

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

Start Hunting!

Translated by