Change or save data .txt

8 views (last 30 days)
Akmal Rahmat
Akmal Rahmat on 22 Nov 2014
Commented: Image Analyst on 23 Nov 2014
a = dlmread('test4.txt');
b = dlmread('test5.txt');
if (a-b)>125
c = (a-b)>125;
c = 0;
c = dlmmwrite('test4.txt','delimiter');
c = dlmwrite('test5.txt','delimiter');
end
hello all. i need help.here is my code. how do i change the data in my .txt file ? when a-b meet my condition i want to change it in both .txt file. i keep getting error. please help me. thank you
  5 Comments
Akmal Rahmat
Akmal Rahmat on 22 Nov 2014
here is the text file. i want to change both file value when it meet the condition where the a-b value more than 125 then the number in the txt file will change to zero.
Guillaume
Guillaume on 22 Nov 2014
Edited: Guillaume on 22 Nov 2014
If you'd answered the question I asked we would be much closer to helping you. So, once again, if
a = [255 255 0 124 126]
b = [255 0 255 126 124]
What final a and b do you expect? Bearing in mind that:
(a-b) == [0 255 -255 -2 2]

Sign in to comment.

Answers (1)

Image Analyst
Image Analyst on 22 Nov 2014
Edited: Image Analyst on 22 Nov 2014
Try this (untested because you didn't attach your text files):
a = dlmread('test4.txt');
b = dlmread('test5.txt');
c =(a-b)>125; % Logical array
a(c) = 0; % Replace elements in a with 0;
b(c) = 0; % Replace elements in b with 0;
% Write updated a and b back out.
dlmwrite('test4.txt', a);
dlmwrite('test5.txt', b);
  10 Comments
Akmal Rahmat
Akmal Rahmat on 22 Nov 2014
a and b are different sizes ? i just resize a to 100x100 and rename it as b ? is my code right?
originally my task is to compare two image that been convert to text file. i attach the image that i will use. all i want is to read each value in both text file then make comparison of it and show the percentage of different between two text file.
a = imread('img2.jpg');
b = imresize(a,[100,100])
dlmwrite('test4.txt', b, 'delimiter', ',');
d = dlmread('test4.txt');
e = imread('img1.jpg');
f = imresize(e,[100,100])
dlmwrite('test5.txt', f, 'delimiter', ',');
g = dlmread('test5.txt');
here is my way to convert the image to text file. the problem is how to calculate the different between two text file. sir do you have any idea how i should do it. i am stuck here.
Image Analyst
Image Analyst on 23 Nov 2014
Use my code in the comment, but have C be this:
c = a ~= b; % Logical array
This will calculate where a and b are different, like you asked for.

Sign in to comment.

Tags

No tags entered yet.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!