Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Need some help with matlab 1

Status
Not open for further replies.

Capzos

Computer
Aug 8, 2005
7
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 :)
 
Replies continue below

Recommended for you

There is a perfectly good Matlab forum here

TTFN



 
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

 
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
 
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.
 
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
 
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!
 
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
 
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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor