×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

How can I implent this in matlab?

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?

RE: How can I implent this in matlab?

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.

RE: How can I implent this in matlab?

(OP)
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.

RE: How can I implent this in matlab?

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.

RE: How can I implent this in matlab?

(OP)
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.

RE: How can I implent this in matlab?

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.

RE: How can I implent this in matlab?

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
 

RE: How can I implent this in matlab?

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

RE: How can I implent this in matlab?

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

RE: How can I implent this in matlab?

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

RE: How can I implent this in matlab?

You are correct.  I did not understand the problem.  I believe your answer is the cleanest and most efficient.

RE: How can I implent this in matlab?

(OP)
@VisiGoth - no my second example is correct, my first is wrong, I have it sorted out now anyway, thanks for your help

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources