Where is error? My program showed my only WYKRYTO, but I don't know what.
fprintf('\nWYKRYTO: ');
if (kaszel == max([kaszel, smiech, krzyk, chrzakanie]))
fprintf('kaszel');
elseif (smiech == max([kaszel, smiech, krzyk, chrzakanie]))
fprintf('smiech');
elseif (krzyk == max([kaszel, smiech, krzyk, chrzakanie]))
fprintf('krzyk');
elseif (chrzakanie == max([kaszel, smiech, krzyk, chrzakanie]))
fprintf('chrzakanie');
end

13 件のコメント

Matt J
Matt J 2014 年 1 月 21 日
Works fine for me.
AJ von Alt
AJ von Alt 2014 年 1 月 21 日
What are the values of kaszel, smiech, krzyk, and chrzakanie ?
Your programs seems to work properly when I set them to random values.
You should also add a fprintf('\n') after end to improve readability.
Monika
Monika 2014 年 1 月 21 日
Kaszel, smiech, krzyk, and chrzakanie are my output. They are name of my signals.
kaszel -cough smiech - laugh krzyk - shout chrzakanie - grunt
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
Are they strings?
Patrik Ek
Patrik Ek 2014 年 1 月 21 日
Is the code in your script identical with the code in the question? Including new lines and so? In that case you need to add 3 dots after each comma where you start writing on next line. Otherwise MATLAB assumes a matrix
[1 2 3; 4]
Which have wrong dimensions.
Monika
Monika 2014 年 1 月 21 日
編集済み: Monika 2014 年 1 月 21 日
Cough, grunt, shout and laught are they name for voice signals
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
What is class(kaszel) ?
Monika
Monika 2014 年 1 月 21 日
This code is the same like in my script.
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
What is class(kaszel) ? Run your program and at the end of that section
disp(class(kaszel))
and tell us what the output was.
Monika
Monika 2014 年 1 月 21 日
disp(class(kaszel))
double
Walter Roberson
Walter Roberson 2014 年 1 月 21 日
Please show
size(kaszel), size(smiech), size(krzyk), size(chrzakenie)
Monika
Monika 2014 年 1 月 21 日
編集済み: Walter Roberson 2014 年 1 月 21 日
Size of my signal is depends on which signal will be my input. I have 64 signals. I can make 64 different inputs.
>> disp(class(kaszel))
double
>> size(kaszel)
ans =
107 13
>> size(smiech)
ans =
107 13
>> size(krzyk)
ans =
107 13
>> , size(chrzakanie)
ans =
107 13
Monika
Monika 2014 年 1 月 21 日
編集済み: Walter Roberson 2014 年 1 月 22 日
My teacher told me, that I can the above code I can write in two lines.
[junk classID(i)] = max([sum(kaszel)
acc = sum(classID==labels)/length(labels)
But I don't know, how I should use acc

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2014 年 1 月 21 日

0 投票

max([array1, array2])
means
max(horzcat(array1, array2))
which in turn means
max(horzcat(array1, array2), [], 1)
which will calculate the column-by-column maximum of horzcat(array1, array2), which is going to give you a result which is 1 x (size(array1,2) + size(array2,2)) .
And then you try to compare the entire array array1 to the result of the max(), so you are comparing
size(array1,1) x size(array1,2)
to
1 x (size(array1,2) + size(array2,2))
and you can see by examination that the only way that can work is if array1 only has a single row and array2 is empty. (Well, that case would be treated differently by MATLAB, but you would still end up with mismatched lengths for the comparison)
Taking into account that you have entire arrays to be compared, what do you want your output to be? A 2D cell array of strings that indicates at each location which of the four arrays was the maximum at that point ? Or do you wish to know which of the four has the greatest average magnitude? Or something else?

9 件のコメント

Monika
Monika 2014 年 1 月 21 日
I would like to know which of the four arrays was the maximum at that point.
Walter Roberson
Walter Roberson 2014 年 1 月 22 日
T = cat(3, kaszel, smiech, krzyk, chrzakanie);
[maxval, IDs] = max(T, [], 3);
now IDs(J,K) for position I, J will be 1 for kaszel, 2 for smiech, 3 for krzyk, 4 for chrzakanie
Monika
Monika 2014 年 1 月 22 日
編集済み: Monika 2014 年 1 月 22 日
I changed my code for:
if true
% code
end
T = cat(3, kaszel, smiech, krzyk, chrzakanie);
if true
% code
end
if true
% code
end
[maxval, IDs] = max(T, [], 3);
if true
% code
end
Now program showed
if true
% code
end
WYKRYTO
if true
% code
end
but should show
if true
% code
end
WYKRYTO: kaszel ( type of signal)
if true
% code
end
Matt J
Matt J 2014 年 1 月 22 日
Your responses are hard to read, because you are using the
button incorrectly. You are supposed to first highlight the code and then press the {}Code formatting button. The repeated occurences of
if true
% code
end
should not be there.
Monika
Monika 2014 年 1 月 22 日
I changed my code for:
T = cat(3, kaszel, smiech, krzyk, chrzakanie);
[maxval, IDs] = max(T, [], 3);
Now program showed
WYKRYTO:
======================================================================
but should show
WYKRYTO: kaszel ( type of signal)
Walter Roberson
Walter Roberson 2014 年 1 月 22 日
In the code fragment you show, you do not display the output at all.
And remember, you asked which of the 4 arrays is maximum at each point, so that is going to be 107 x 13 different answers.
Are you trying to figure out which array is "most" maximum? The answer will not necessarily be unique, but you can use
accumarray(IDs(:), 1)
to get the counts of how many times each array was the maximum. You can then use max() on that to attempt to figure out which of the four is the majority -- but remember to take ties into account.
Monika
Monika 2014 年 1 月 22 日
編集済み: Monika 2014 年 1 月 22 日
Now program showed me:
Probka: kaszel
WYKRYTO: ans =
644
308
280
159
I would like to see words (cough, shout, laugh or grunt)
What should I do?
Walter Roberson
Walter Roberson 2014 年 1 月 22 日
Please show your current code fragment.
Monika
Monika 2014 年 1 月 22 日
fprintf('\nObliczone wartości prawdopodobieństwa przynależenia do poszczególnych klas:\n');
fprintf('Kaszel: %d\nŚmiech: %d\nKrzyk: %d\nChrząkanie: %d\n',kaszel,smiech,krzyk,chrzakanie);
fprintf('\nProbka: %s',pliki(numer_pliku).klasa);
wavplay(sygnal,Fs);
fprintf('\nWYKRYTO: ');
T = cat(3, kaszel, smiech, krzyk, chrzakanie);
[maxval, IDs] = max(T, [], 3);
accumarray(IDs(:), 1)
fprintf('\n======================================================================');
end
fprintf('Zakończono działania skryptu\n');
else
fprintf('Niewystarczająca liczba próbek aby wyznaczyć GMM!');
fprintf('\nNaciśnij dowolny klawisz, aby kontynuować...');
pause;
rozpoznawanie_dzwiekow;
end

サインインしてコメントする。

その他の回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 21 日

0 投票

Maybe you want
fprintf('\\nWYKRYTO: ');

3 件のコメント

Monika
Monika 2014 年 1 月 21 日
No, now is different error: Probka: kaszel\nWYKRYTO: ??? Error using ==> eq Matrix dimensions must agree
Azzi Abdelmalek
Azzi Abdelmalek 2014 年 1 月 21 日
If you give some data we can test your code.
Monika
Monika 2014 年 1 月 21 日
編集済み: Walter Roberson 2014 年 1 月 21 日

サインインしてコメントする。

per isakson
per isakson 2014 年 1 月 21 日

0 投票

2 件のコメント

Matt J
Matt J 2014 年 1 月 21 日
Hard to imagine that applies to max() operations. I'm not encountering issues, at least.
per isakson
per isakson 2014 年 1 月 22 日
編集済み: per isakson 2014 年 1 月 22 日
Agree, but it's a good habit not to use "==" with floats.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

質問済み:

2014 年 1 月 21 日

コメント済み:

2014 年 1 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by