Change or save data .txt

1 次查看(过去 30 天)
Akmal Rahmat
Akmal Rahmat 2014-11-22
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 个评论
Akmal Rahmat
Akmal Rahmat 2014-11-22
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 2014-11-22
编辑:Guillaume 2014-11-22
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]

请先登录,再进行评论。

回答(1 个)

Image Analyst
Image Analyst 2014-11-22
编辑:Image Analyst 2014-11-22
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 个评论
Akmal Rahmat
Akmal Rahmat 2014-11-22
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 2014-11-23
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

尚未输入任何标签。

Community Treasure Hunt

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

Start Hunting!

Translated by