I have a matrix read from a text file and I want to subtract more matrix, delimited by the repeating line: 9999 0 0 0 0 0. I want to have as a result 5 different matrix, in this case. How can I do? thank you

3 views (last 30 days)
501 1.547 0 0 0 0
500 73.164 100.4764 333.3890 1.500 00
502 58.793 99.6720 160.0586 1.500 00
9999 0 0 0 0 0
502 1.560 0 0 0 0
501 58.790 100.4551 60.7974 1.500 00
503 37.525 99.3758 200.0799 1.500 00
9999 0 0 0 0 0
503 1.592 0 0 0 0
502 37.524 100.8832 197.9390 1.500 00
504 69.050 99.8927 277.4128 1.500 00
9999 0 0 0 0 0
504 1.630 0 0 0 0
503 69.060 100.2973 130.6244 1.500 00
501 52.676 101.3383 229.5360 1.500 00
9999 0 0 0 0 0
501 1.547 0 0 0 0
504 52.675 98.8623 77.7161 1.500 00
500 73.164 100.4764 333.3890 1.500 00
As result for example, the first one should be
501 1.547 0 0 0 0
500 73.164 100.4764 333.3890 1.500 00
502 58.793 99.6720 160.0586 1.500 00
the second one
502 1.560 0 0 0 0
501 58.790 100.4551 60.7974 1.500 00
503 37.525 99.3758 200.0799 1.500 00
..........the last one
501 1.547 0 0 0 0
504 52.675 98.8623 77.7161 1.500 00
500 73.164 100.4764 333.3890 1.500 00
  5 Comments
Stephen23
Stephen23 on 8 Jun 2015
Edited: Stephen23 on 8 Jun 2015
@Loghin Ana-Maria: Can you please upload the actual file? This makes us helping you a lot easier.

Sign in to comment.

Accepted Answer

Stephen23
Stephen23 on 8 Jun 2015
Edited: Stephen23 on 8 Jun 2015
EDIT: to use the newly uploaded data file.
Probably the easiest way to split this would be to do this after reading the file into MATLAB:
% Read the file as text:
fid = fopen('drumuire.txt','rt');
C = cell2mat(textscan(fid,'%f%f%f%f%f%f'));
fclose(fid);
% identify groups between 9999's:
idx = [1,diff(C(:,1)'~=9999)];
idy = find(idx<0)-find(idx>0);
idy(2,:) = 1;
% Split data into a cell array:
D = mat2cell(C,idy(:),size(C,2));
D(2:2:end) = []; % optional...
This code automatically adjusts to the number of rows (i.e. must not be groups of three), but assumes that the rows with 9999 only occur individually (i.e. are not grouped together, two or more rows), and that the first row is not a 9999 row but that the last row is. This code returns all of the data in a cell array:
>> D
D =
[3x6 double]
[3x6 double]
[3x6 double]
[3x6 double]
[3x6 double]
>> D{1}
ans =
501.0000 1.5470 NaN NaN NaN NaN
500.0000 73.1640 100.4764 333.3890 1.5000 0
502.0000 58.7930 99.6720 160.0586 1.5000 0

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!