text - How to access to numbers from *.txt file in matlab? -


i have data.txt file like:

123 124 125 126

i want compare these number against num

my code this

 data= textread('data.txt','%d');     num = 125;     if num == data          b = 1;     else          b = 0;     end 

but answer shows 0 ( b = 0 )

how scan these numbers?

here quote doc page of eq function (the functional form of == operator):

a == b 

if 1 input scalar , other nonscalar array, scalar input treated if array having same dimensions nonscalar input array. in other words, if input number 100, , b 3-by-5 matrix, treated if 3-by-5 matrix of elements, each set 100. matlab returns array of same dimensions nonscalar input array.

and here relevant section docs of if statement:

if expression     statements end 

an evaluated expression true when result nonempty , contains nonzero elements (logical or real numeric). otherwise, expression false.

so perhaps meant use:

if any(data == num)     disp('number found') end 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -