How can I implent this in matlab?
How can I implent this in matlab?
(OP)
I have a file called input.dat. The file contains the following data.
0 .75
1 .23486
2 .73965
.
.
200 .648
1 .47
Basically the input file has 1-200 in order 30 times and the right column contains a num.
What I want to do is take in this file, plot all the numbers which correspond to zero in the left column, plot all the numbers which correspond to 1 in the left column etc. Does anyone know how this could be done?
0 .75
1 .23486
2 .73965
.
.
200 .648
1 .47
Basically the input file has 1-200 in order 30 times and the right column contains a num.
What I want to do is take in this file, plot all the numbers which correspond to zero in the left column, plot all the numbers which correspond to 1 in the left column etc. Does anyone know how this could be done?





RE: How can I implent this in matlab?
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: How can I implent this in matlab?
I cannot do that because im looking to plot all xy values where the 1st colunm is zero, then all xy values where the 1st colunm is one etc..
So in the end I will have 200 lines, each line been made from 30 points.
RE: How can I implent this in matlab?
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: How can I implent this in matlab?
1 .54 .46
2 .57 .92
3 .65 .34
.
.
.
199 .84 .34
200 .34 .45
1 .65 .56
2 .67 .19
.
.
The left hand column will go from 0 to 200 30 times (so the file is 6000 lines long). Column 2 is my x values, column 3 is my y values.
I need to be able to plot it so line 0 will be created from all the x and y points which have a 0 in the left hand column and line 1 will be created from all the x and y points which have a 1 in the left hand column etc...
So in the end I will have plotted 200 lines, each line will be made from 30 xy points.
I hope thats clearer, thanks for your help.
RE: How can I implent this in matlab?
ie new_array(x,y,page)=old_array(page,x,y);
and then plot each page as a new curve
Cheers
Greg Locock
Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
RE: How can I implent this in matlab?
[ nRow, nColumn ] = size( input );
nLine = 201;
nPage = nRow / nLine; % You better be sure, or check here
plotData = zeros( nLine, nPage ); % malloc
for iLine = 1 : nLine
indexZero = find( input( :, iLine ) == ( iLine - 1 ) );
plotData( iLine, : ) = input( indexZero, 2 ).'; % Make data into a row
end
iFigure = 0;
iFigure = iFigure + 1;
figure( iFigure )
plot( plotData.' )
grid
RE: How can I implent this in matlab?
CODE
x = reshape(input(:,2),[201,30])';
y = reshape(input(:,3),[201,30])';
plot(x,y);
M
--
Dr Michael F Platten
RE: How can I implent this in matlab?
There are only two coloumns in his data (the second example is incorrect it seems). Also, the desire is to end up with a 2X2 matrix with the first colimumn being from 0:200. Each row from the second term to the end will be the data points that correspond to the first element in that row. There may be a clever way to vectorize using your reshape example, but I am not sure. Otherwise, I thought a loop would be a brute force way of organizing the data.
J
RE: How can I implent this in matlab?
"... end up with a 2X2 matrix with the first colimumn being from 0:200."
I don't get what you mean by this.
"There are only two coloumns in his data (the second example is incorrect it seems)."
The OP's 3rd post seems very explicit.
"The left hand column will go from 0 to 200 30 times (so the file is 6000 lines long). Column 2 is my x values, column 3 is my y values."
The only assumption that I made was that he/she meant "6030 lines long"
M
--
Dr Michael F Platten
RE: How can I implent this in matlab?
RE: How can I implent this in matlab?