0

I am trying to load ascii files into Matlab which contain 1020 rows and two columns of spectral data. When I use dlmread like below, Matlab turns this into a matrix N, which is what I want:

N = dlmread('alummatrix.asc')

However, I want it to read only the first 80 rows of data and ignore the rest, and then do this for all .asc files in a directory. Also, I want the decimal number not to change or get rounded. It's outputting my data 5 decimal figures to the left of the original data. Also, I'd like it to retain its original notation and not to round:

It gives me:

 N =
    1.0e+05 *
    0.0384    0.3374

When I just want it to show up like:

 N = 
     3838     33738
Adriaan
  • 17,741
  • 7
  • 42
  • 75
Svet
  • 11
  • 5
  • Your issue is with the way MATLAB is formatting numbers for output. The duplicate link should help you address this issue. `tl;dr` - In the Command Prompt, type in `format long g;` then try your code again after. – rayryeng Jan 20 '16 at 20:53
  • Thanks! That worked. But how do I get it to read only the first 80 rows of data and ignore the rest? And then do this for all ascii files in a dir, saving each as a different matrix name? – Svet Jan 20 '16 at 20:58
  • (1) For `dlmread`, it is possible but you need to know how many columns there are in each file. If you don't know this or if you have a variable number of columns in each file, you don't have a choice but to read the entire matrix then remove the rows you don't want. (2) Doing it for multiple files wasn't included in your original question. Please edit your question so you are specifying everything you want solved and I will reopen. – rayryeng Jan 20 '16 at 21:11
  • Ok. There are 1020 rows and two columns of spectral data in each .asc file, as stated in my original question. But I'll use the option where I read the entire matrix and then remove... – Svet Jan 20 '16 at 21:14
  • I'm new to this site... Has this been closed or should I repost the part, "how do I get it to read only the first 80 rows of data and ignore the rest? And then do this for all ascii files in a dir, saving each as a different matrix name?" Thanks! – Svet Jan 20 '16 at 22:06
  • You need to be patient. I've been juggling with other things at work currently. I'm in the middle of writing you an answer. You'll notice that Stack Overflow mostly consists of volunteers. If we don't get back to you right away, then that's very natural. – rayryeng Jan 20 '16 at 22:08
  • I'm not being impatient. I'm just new to this site and trying to grasp all these functionalities. I was just trying to understand whether you wanted me to repost the question separately or whether this conversation was deactivated or what. I saw that you posted a comment with the following example in it but I can't find that thread now. Thanks for the help. folder = fullfile('path', 'to', 'folder'); >> f = dir(fullfile(folder, '*.asc')); >> matrices = struct(); >> for ii = 1 : numel(f) name = fullfile(folder, f(ii).name); O = dlmread(name); matrices.(f(ii).name) = O(1:80,:); – Svet Jan 20 '16 at 22:57

1 Answers1

0

Use this line of code:

N = dlmread('alummatrix.asc','',[0 0 80 0]);

Good luck!

VahidB
  • 11
  • 4