Change or save data .txt

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 comentarios

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Nov. de 2014
what is f?
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
sorry sir. i just copy from my other code. already edit my coding above.
Guillaume
Guillaume el 22 de Nov. de 2014
If
a = [255 255 0 124 126]
b = [255 0 255 126 124]
What result do you expect?
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 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 el 22 de Nov. de 2014
Editada: Guillaume el 22 de Nov. de 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]

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 22 de Nov. de 2014
Editada: Image Analyst el 22 de Nov. de 2014

0 votos

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 comentarios

Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
it doesnt work sir. here im attach the .txt file.
Guillaume
Guillaume el 22 de Nov. de 2014
it doesn't work is not an helpful comment. What happens and what did you expect to happen? We can't read your mind.
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
sorry sir. from the attach file i give. there are a lot of number and i want to set, if the number is more than 125 then it will change to 0. because later i want to make percentage of it. how much number that more than 125.
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
Editada: Akmal Rahmat el 22 de Nov. de 2014
@imageanalyst @guilaume the code you give can run but it doesn't show any result. the number in the text file doesnt change at all. i expect the number in text file change to 0 when it meet the condition.
Image Analyst
Image Analyst el 22 de Nov. de 2014
Editada: Image Analyst el 22 de Nov. de 2014
Akmal, there are no array elements where a is more than 125 greater than b. That's why "it didn't work.". Here, try this code
clc;
clearvars;
close all;
workspace;
fontSize = 33;
a = dlmread('test4.txt');
b = dlmread('test5.txt');
c =(a-b)>125; % Logical array
subplot(2,3,1);
imshow(uint8(a));
title('a', 'FontSize', fontSize);
subplot(2,3,2);
imshow(uint8(b));
title('b', 'FontSize', fontSize);
subplot(2,3,3);
imshow(c, []);
title('c', 'FontSize', fontSize);
a(c) = 0; % Replace elements in a with 0;
b(c) = 0; % Replace elements in b with 0;
subplot(2,3,4);
imshow(uint8(a));
title('New a', 'FontSize', fontSize);
subplot(2,3,5);
imshow(uint8(b));
title('New b', 'FontSize', fontSize);
% Write updated a and b back out.
% dlmwrite('test4.txt', a);
% dlmwrite('test5.txt', b);
and observe this result:
Note how there are no white pixels in c? That means the condition of a-b>125 was never true for any pixel. Perhaps you're using the wrong test4.txt.
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
Editada: Akmal Rahmat el 22 de Nov. de 2014
sorry sir im new in matlab and i have a lot to learn here.. i dont understand why you said no array element in a? in the attach file test4 and test5 , there a number that more than 125 so why do you said that condition of (a-b)>125 is not true?
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 2014
Editada: Akmal Rahmat el 22 de Nov. de 2014
first of all is how i get the test4 and test5 is i change/convert the image to text file. then i want to calculate each value in the text file then categorize it into two part. first is <=125 and >125. so later i can make percentage of it. this is how i change the image to text file. help me correct my code if there is bad code. and really sorry for my english if it bad.
a = imread('img2.jpg');
b = imresize(a,[100,100])
dlmwrite('test4.txt', b, 'delimiter', ',');
d = dlmread('test4.txt');
[x,y] = size(d);
Image Analyst
Image Analyst el 22 de Nov. de 2014
Well, now a and b are different sizes, and you've introduced a "d". Also you forgot to attach 'img2.jpg'. But anyway, the additional code you posted in no way explains why you think the values in test4 should be 125 greater than in test5.
Finally, the unneeded statement
[x,y] = size(d);
is decpetive because x is usually the horizontal dimension but here you have it as the number of rows, which is the vertical dimension. It should be one of these:
[y, y] = size(d); % or
[rows, columns] = size(d);
But that really has nothing to do with why a is not greater than b by 125.
Akmal Rahmat
Akmal Rahmat el 22 de Nov. de 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 el 23 de Nov. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 22 de Nov. de 2014

Comentada:

el 23 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by