简体   繁体   中英

MATLAB: changes in vector elements

I have a some vectors of different large sizes and their value is between 0 and 1 . I want to save those indices of elements which there would be any changes in decimal. For an small example, let's assume

     V=[0.02,0.1,0.4,0.0054,0.05];

Now the ouptput for this should be as

     i={2,4,5}

Would you please let me know how it can be done?

count = arrayfun(@(x) regexp(num2str(x),'\.','split'),V, 'UniformOutput', false)
dp = cell2mat(arrayfun(@(x) length(x{2}),count, 'UniformOutput', false))
find(diff(dp))+1

I did it this way. First I split the numbers and next i find the length of the second term and lastly, I find whether the length is different from its previous..

As suggested by @Luis Mendo (including his suggestion with removing ~= 0 ), here the comment as answer. You can use the logarithm function to determine your number of decimals for you.

i = find(diff(floor(log10(V))))+1

Be sure to use floor to have integer values you can compare to 0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM