Percentage from two text file and send to axes in GUI.

Hello all. I have some problem here. How can i calculate similarity percentage from two text file then send it to one of my axes in GUI ? Here i attach my text file. In my text file only have 0 and 1 only. i try to use this code but it calculate the difference by line only. I want to store how many 0 and 1 i have then make the percentage of it. after that send the result to the axes in my GUI. Thanks guys.
visdiff('testa.txt', 'test1.txt', text);

Answers (2)

Akmal - if we assume that your two commas separated data files are of the same size (identical number of rows and columns), then we can use csvread to read the data from each into two different matrices
X = csvread('test2.txt');
Y = csvread('test3.txt');
Now, find those matrix indices that correspond to differences between the two
diffIdcs = find(X~=Y);
So now you have a list of differences (from which you can determine which indices of X and Y correspond to zeros and ones), and you can determine a percentage difference as
diffPercent = numel(diffIdcs)/numel(X);

11 Comments

Sorry to disturb you sir. I dont understand why the result doesn't show any number or percentage but it show the image.
ogit this error sir while using your code.
Error using ~=
Matrix dimensions must agree.
Error in ProjectGray>COMPARE_Callback (line 118)
a4 = find(a2~=a3);
Error in gui_mainfcn (line 95)
feval(varargin{:});
Error in ProjectGray (line 17)
gui_mainfcn(gui_State, varargin{:});
Given the example you provided, my assumption was that the two files, when loaded, would create two matrices of the same dimension. If they are of different dimension, as your error message is indicating, then how would you go about comparing the two?
I use your coding above sir to make comparing with little adjustment.
diffPercent = (numel(diffIdcs)/numel(X))*100;
i already do my correction from above problem. but sir. the result shows in image not number. why ? below i attach the picture of result i get.
Akmal - how are you using diffPercent once you do the above calculation? Isn't diffPercen just a scalar, so how do you convert it to an image (which is shown in black in your attached png)?
a2 = csvread('testa.txt');
a3 = csvread('test1.txt');
a4 = find(a2~=a3);
a5 = (numel(a4)/numel(a2))*100;
axes(handles.axes10)
imshow(a5);
im just using this code. then it shows the picture. the text file i attach before are contains an image. Firstly , i insert the image then i save it into text file using below code.
global x
a =rgb2gray(x);
prewitts=edge(a,'prewitt');
b = imresize(prewitts,[100,100]);
dlmwrite('test1.txt',b, 'delimiter', ',');
axes(handles.axes2);
imshow(prewitts);
then im using the code you give to make comparison between two text file. Can you help me sir ? is there any way for me to contact u directly ? email ? im reaching my duedate to submit this project. really need your help sir. just got a weeks to submit this.
See Thorsten's answer on how to build the difference image.
how to transfer the result to GUI ? in axes ? based on @Thorsten code..
Wouldn't it be
axes(handles.axes10)
imshow(D);
based on what you have shown previously?
already found it sir. i use this code
set(handles.edit1,'String',a5);
and how can show result in words in my GUI ? below is my code. is it right ?
if a5 == 0
a6 = evalc('True Image');
set(handles.edit5,'String',a6);
elseif a5 ~=0
a7 = evalc('False Image');
set(handles.edit5,'String',a6);
end
i keep getting error for this code. please help me sir
Akmal - please include the error message. What is your intent behind using evalc, just to write some text?

Sign in to comment.

Read the text files. Make sure you have the right names (you provide files test2.txt and test3.txt but use different files testa.txt and test2.txt in your code)
a2 = csvread('testa.txt');
a3 = csvread('test1.txt');
Compute the difference
D = abs(a2 - a3);
To show the difference image, use
imshow(D)
To display the percentage of '1's in D
perc = numel(find(D == 1))/numel(D)*100;
disp(['Pixels that differ: ' num2str(perc) '%'])

Categories

Find more on Scripts in Help Center and File Exchange

Asked:

on 28 Nov 2014

Commented:

on 3 Dec 2014

Community Treasure Hunt

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

Start Hunting!