Change or save data .txt
8 views (last 30 days)
Show older comments
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
Answers (1)
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
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.
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!