Make different matrix from loaded data separated by blank line

3 views (last 30 days)
I can make matrix x and y from data.dat which is consist by 2 columns using this code:
load data.dat
x=data(:,1);
y=data(:,2);
what if i want to make matrix x1, x2, ... xn and the same with y, where x1, x2, are separated by blank line like this in the data.dat
54.510 1.420
55.294 1.819
55.859 1.935
55.999 2.381
9.017 1.600
9.518 1.916
9.868 2.217
9.896 2.368
10.113 2.533
10.424 2.552
.... ....
based on example data, I expect
x1=[54.510;55.294;55.859;55.999]
x2=[9.017;9.518;9.868;9.896;10.113;10.424]
y1=[1.420;1.819;1.935;2.381]
y2=[1.600;1.916;2.217;2.368;2.533;2.552]
Thank You
  3 Comments
Joseph Cheng
Joseph Cheng on 23 Jun 2014
Edited: Joseph Cheng on 23 Jun 2014
I would suggest using cells instead of having x1, x2 ... xn. such that x1 = x{1} and x2 = x{2}, so on and so on.
something along these lines.
x = 1:40;
spaces = [1 5 10 35]
spaces = [spaces length(x)+1]
for i =1:length(spaces)-1
X{i} = x(spaces(i):spaces(i+1)-1)
end
given you know where your "new" variable separators are.

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!