MATLAB: How to read this txt.data in matlab

graphtxt

I'm searching for answer that can read this data in matlab.
Since this dataset's variables are departed with colon, I can't read this files in matrix.
I want to put data 1 in x coordinate, and data 2 in y coordinate.
To show this data in 2D, I want to put only two data which are departed in colon.
To show this data in 3D, I want to put all three data in 3 Dimension graph.

Best Answer

Use the textscan function to read it:
fidi = fopen('data-ex1.txt');
Dc = textscan(fidi, '%f 1:%f 2:%f', 'CollectOutput',1);
D = cell2mat(Dc);
figure(1)
plot(D(:,2), D(:,3))
grid
title('2D Plot')
figure(2)
plot3(D(:,1), D(:,2), D(:,3))
grid on
title('3D Plot')
xlabel('X')
ylabel('Y')
zlabel('Z')
The ‘D’ matrix has the numeric results. I assume you do not want the ‘1:’ and ‘2:’, so the format string in the textscam call eliminates them when in reads the file. The ‘1:’ values are ‘D(:,2)’, and the ‘2:’ values are ‘D(:,3)’. The column of ±1 are in ‘D(:,1)’.
Change the plots to produce the result you want.