Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: load column in from text file
Replies: 12   Last Post: Dec 11, 2012 3:47 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Fiboehh

Posts: 8
Registered: 12/15/10
Re: load column in from text file
Posted: Dec 8, 2012 12:12 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

> 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?



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.