Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations KootK on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I implent this in matlab?

Status
Not open for further replies.

sysqa10

Computer
Oct 16, 2005
4
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?
 
Replies continue below

Recommended for you

when you read it in you'll get a matric two colums wide by 6000 rows,so just plot the second column against the first.

Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Actually sorry, I just realised that I will need 3 columns (im very tired).
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.
 
Sorry, you'll have to include an example of the input file, i can't see what you mean.

Cheers

Greg Locock

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
0 .75 .455
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.
 
I'd create a 3d array using column 1 as the page

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.
 
load input.dat
[ 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
 
Have I missed the point here? Is there anything wrong with this?

Code:
load input.dat;
x = reshape(input(:,2),[201,30])';
y = reshape(input(:,3),[201,30])';
plot(x,y);

M

--
Dr Michael F Platten
 
M,
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
 
Sorry, you have lost me completely there.

"... 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
 
You are correct. I did not understand the problem. I believe your answer is the cleanest and most efficient.
 
@VisiGoth - no my second example is correct, my first is wrong, I have it sorted out now anyway, thanks for your help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor