Percentage from two text file and send to axes in GUI.
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(2 个)
Geoff Hayes
2014-11-28
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 个评论
Geoff Hayes
2014-12-3
Akmal - please include the error message. What is your intent behind using evalc, just to write some text?
Thorsten
2014-12-2
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) '%'])
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 LaTeX 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!