Percentage from two text file and send to axes in GUI.
Show older comments
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)
Geoff Hayes
on 28 Nov 2014
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
Akmal Rahmat
on 30 Nov 2014
Edited: Akmal Rahmat
on 30 Nov 2014
Akmal Rahmat
on 30 Nov 2014
Geoff Hayes
on 30 Nov 2014
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?
Akmal Rahmat
on 1 Dec 2014
Edited: Akmal Rahmat
on 1 Dec 2014
Geoff Hayes
on 2 Dec 2014
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)?
Akmal Rahmat
on 2 Dec 2014
Geoff Hayes
on 2 Dec 2014
See Thorsten's answer on how to build the difference image.
Akmal Rahmat
on 2 Dec 2014
Geoff Hayes
on 2 Dec 2014
Wouldn't it be
axes(handles.axes10)
imshow(D);
based on what you have shown previously?
Akmal Rahmat
on 3 Dec 2014
Geoff Hayes
on 3 Dec 2014
Akmal - please include the error message. What is your intent behind using evalc, just to write some text?
Thorsten
on 2 Dec 2014
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) '%'])
1 Comment
Akmal Rahmat
on 2 Dec 2014
Categories
Find more on Scripts 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!