×
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

Need some help with matlab

Need some help with matlab

Need some help with matlab

(OP)
I am having a page full of data which comes from the sensor readings...which i have to scan through my program and check to see if there are any changes.. but my initial issue is that i need to write a function in matlab which takes the file which contains the data and gives an output saying that there are changes in the reading.. or there isnt any.. as i am quiet new to matlab i  am running out of ideas as to how to do it...
    .. i would also like an advice on how to scan a matrix and compare the value with the value which is in the same column but the previous row. i know to do it in c.. but it is giving me a hard time in matlab.. please help me if anyone knows the answer to it...

Regards,
Capzos :)

RE: Need some help with matlab

There is a perfectly good Matlab forum here

TTFN



RE: Need some help with matlab

Scanning in could be a little work if it is not in ASCII with whitespace.  If you have a nice ascii text file of just numbers, with no hearders, then the MATLAB help will show you how to do it.  Giving help without knowing your format would only add to the confusion.

The way to do your second question is similar to C++ valarray slices, only maybe a little easier.

You could loop through all of your new columns and test against your previous old columns (this is just a repeat of your question unless I misunderstood it.)

There are more details needed, this is only non dunctional psuedo code.

load oldData
load newData  % Assume only one column bigger, rows the same


[r_, c_ ] = size( newData );

for iColumn = 2 : c_
   indexDifferent = find( newData( :, iColumn ) ~= oldData( :, iColumn - 1 ) );
   if  ~isempty( indexDifferent % if it is not empty do something important
(
  % do something
)
end

RE: Need some help with matlab

(OP)
hi visigoth,

thanks for your help... here a bit more detail....

it is a data of 8 columns and 1000,s of rows.. but the columns are constant (8).. and it will be in the normal .txt format and quite huge.. sometimes the rows extending to 10000 lines...the main prob is that i have to do it using only matlab.

  please see if u could find a way out.

capzos

RE: Need some help with matlab

Aha, I did not pay attention to your problem. If you only have to check the new row agains the previous row (assuming that a row is added for each new "measurement"), then you could use the diff function and eliminate the loop.

Try this:
[ nRow, nColumn ] = size( newData );

derivatveOfData = diff( newData );  % works on a column
indexChangeIndicator = find( abs( derivatveOfData ) ) > 0 );

columnOfChange = 1 + floor( indexChangeIndicator / nRow );
rowOfChange = 1 + indexChangeIndicator - floor( indexChangeIndicator - columnOfChange * nRow );

Now you know what row has a new pice of changed data byt the vector rowOfChange.  If you want to know exactly what column was different, you would use the columnOfChange vector.note that the +1 for the columnOfChange was becuase of the floor function producing a zero and MATLAB using 1 based indexing.  But the +1 for the rowOfChange was because the diff function produces a vecor one shorter than the original data and I thought you would want to know the index into your original data matrix.

RE: Need some help with matlab

(OP)
Dear Visigoth,
thanks for the help again.. one good solution i found was using the inbuilt find function. i have done some code optimization. find can directly get the rows and columns.. so i modified it like this

[ nRow, nColumn ] = size( newData );
derivatveOfData = diff( newData )
[mRow, mColumn] = find(derivatveOfData)

FYI,
 changing it to round instead of floor in columnOfChange worked.. but the rowOfChange gave wrong values.. so i went hunting for some solution and found the deeper use of find.

Enough for today.. will come up with somemore problems tomorrow..

Thanks a lot,
Regards,
Capzos

RE: Need some help with matlab

Sorry, you are correct.  The find column must use the nRow of the smaller diif'ed matrix.  Also, your code is much cleaner.  Good work!

RE: Need some help with matlab

(OP)
hi,

  when i use the save option in matlab, the answers that is saved is in floating point format for e.g, 5.7600000e+002  8.7690000e+003  1.7540000e+003  6.7700000e+002.. but i want it in the normal integer format like 5760 8769 1754 677 .... the command i am using is save myData.txt myData -ascii.... could u please help me out of this... coz its convinient to anlyse the data int the normal format...

thanks,
capzos

RE: Need some help with matlab

You could try converting your integers into ascii characters inside of MATLAB as a string, then save the strings.  That is a little bit of work, but could be done.

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