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

2 visualizzazioni (ultimi 30 giorni)
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);

Risposte (2)

Geoff Hayes
Geoff Hayes il 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 Commenti
Akmal Rahmat
Akmal Rahmat il 3 Dic 2014
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
Geoff Hayes
Geoff Hayes il 3 Dic 2014
Akmal - please include the error message. What is your intent behind using evalc, just to write some text?

Accedi per commentare.


Thorsten
Thorsten il 2 Dic 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) '%'])

Community Treasure Hunt

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

Start Hunting!

Translated by