Make different matrix from loaded data separated by blank line

조회 수: 4 (최근 30일)
Dicky
Dicky 2014년 6월 23일
편집: Joseph Cheng 2014년 6월 23일
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
Joseph Cheng
Joseph Cheng 2014년 6월 23일
편집: Joseph Cheng 2014년 6월 23일
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.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by