Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.
|
|
Fiboehh
Posts:
8
Registered:
12/15/10
|
|
Re: load column in from text file
Posted:
Dec 8, 2012 12:12 PM
|
|
> d = dir('path\*.txt'); % the result of dir() is _not_ a fname but a > directory structure; make the name more representative > > % preallocate your final result--I'm assuming B is no more than a vector > here--if it's another array a cell array may be more suitable... > BigAns=zeros(length(d),length(B)); > > for k = 1:length(d) > x=importdata(d(k).name); % pull the data into an array > B = your_computation(x); > BigAns(k) = B; % you can, of course, dispense w the intermediary > end > save results.txt BigAns -ASCII > > % the above assumes you're saving across the files instead of a single > file for each of the input files. As you wrote it, you have overwritten > the results and end up w/ only the last case after all that effort. > > --
I have just the same code as you, but MATLAB gives sometimes error with files which work fine if I load them in one by one :s If my ascii-file is named 1_01.txt everything works fine, but if I use 2_01.txt it gives a fellowing error;
Error using importdata (line 137) Unable to open file.
Error in ScienceWeek (line 11) log = importdata(fnames(k).name);
Do you have a clue what is going wrong?
|
|
|
|