Error in c# connecting between matlab and C#

1 次查看(过去 30 天)
Hi, Please anyone can solve this error .In connecting between C# and matlab . I don't usderstand the error .
See the end of this message for details on invoking just-in-time (JIT) debugging instead of this dialog box.
************ Exception Text ************ System.Exception:
... MWMCR::EvaluateFunction error ... Error using ==> vertcat CAT arguments dimensions are not consistent..
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, Int32 numArgsOut, Int32 numArgsIn, MWArray[] argsIn)
at MathWorks.MATLAB.NET.Utility.MWMCR.EvaluateFunction(String functionName, MWArray[] argsIn)
at com.speechR.SpeechR.Recognition(MWArray speechIn, MWArray silence)
Thanks a lot:)
Nada Gamal

回答(1 个)

Kaustubha Govind
Kaustubha Govind 2011-5-4
It looks like the inputs that you are providing are causing a "vertcat CAT arguments dimensions are not consistent" error from MATLAB. It is hard to tell without looking at your code, but you may have a call to VERTCAT, or a statement that performs concatenation using something like:
out = [in1 in2];
Do you have the original MATLAB code? If yes, try constructing the same inputs in MATLAB and invoke the function to debug.
  2 个评论
Nada Gamal
Nada Gamal 2011-5-4
Hi,
Thanks for you reply .
C# code:
public String recognition()
{
String[] s ={ "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten", "Yes", "No", "Hello", "Open", "Close", "Start", "Stop", "Dial", "On", "Off" };
SpeechR speech = new SpeechR();
// string path = Application.StartupPath;
WaveReader wr1 = new WaveReader(File.OpenRead( @"C:\SpeechData\Nada1\1_12.wav"));
IntPtr format = wr1.ReadFormat();
byte[] data1 = wr1.ReadData();
wr1.Close();
WaveReader wr2 = new WaveReader(File.OpenRead(@"C:\SpeechData\silen.wav"));
IntPtr format2 = wr2.ReadFormat();
byte[] data2 = wr2.ReadData();
wr2.Close();
MWArray output = (MWArray)speech.Recognition((MWNumericArray)data1, (MWNumericArray)data2);
String str="";
for (int i = 1; i <= s.Length; i++)
{
if ((MWNumericArray)i == output)
{
str = s[i];
}
}
return str;
}
And Matlab Code is :
function[Modal]=Recognition(speechIn,silence)
% clear all;
% close all;
ncoeff = 13; %Required number of mfcc coefficients
N = 20; %Number of words in vocabulary
k = 3; %Number of nearest neighbors to choose
fs=16000; %Sampling rate
duration1 = 0.15; %Initial silence duration in seconds
duration2 = 2; %Recording duration in seconds
G=2; %vary this factor to compensate for amplitude variations
NSpeakers = 6; %Number of training speakers
% fprintf('Press any key to start %g seconds of speech recording...', duration2);
% pause;
% silence = wavrecord(duration1*fs, fs);
% fprintf('Recording speech...');
% speechIn = wavrecord(duration2*fs, fs); % duration*fs is the total number of sample points
% fprintf('Finished recording.\n');
% fprintf('System is trying to recognize what you have spoken...\n');
speechIn1 = [silence;speechIn]; %pads with 150 ms silence
speechIn2 = speechIn1.*G;
speechIn3 = speechIn2 - mean(speechIn2); %DC offset elimination
speechIn = nreduce(speechIn3,fs); %Applies spectral subtraction
rMatrix1 = mfccf(ncoeff,speechIn,fs); %Compute test feature vector
rMatrix = CMN(rMatrix1); %Removes convolutional noise
Sco = DTWScores(rMatrix,N); %computes all DTW scores
[SortedScores,EIndex] = sort(Sco); %Sort scores increasing
K_Vector = EIndex(1:k); %Gets k lowest scores
Neighbors = zeros(1,k); %will hold k-N neighbors
%Essentially, code below uses the index of the returned k lowest scores to
%determine their classes
for t = 1:k
u = K_Vector(t);
for r = 1:NSpeakers-1
if u <= (N)
break
else u = u - (N);
end
end
Neighbors(t) = u;
end
%Apply k-Nearest Neighbor rule
Nbr = Neighbors
%sortk = sort(Nbr);
[Modal,Freq] = mode(Nbr); %most frequent value
%Word = strvcat('One','Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Yes','No','Hello','Open','Close','Start','Stop','Dial','On','Off');
% if mean(abs(speechIn)) < 0.01
% fprintf('No microphone connected or you have not said anything.\n');
% elseif ((k/Freq) > 2) %if no majority
% fprintf('The word you have said could not be properly recognised.\n');
% else
% fprintf('You have just said %s.\n',Word(Modal,:)); %Prints recognized word
% c=Word(Modal,:); %match the number of file with word
%end
Thanks a lot
Nada Gamal :)
Kaustubha Govind
Kaustubha Govind 2011-5-4
My best bet is that the error comes from:
speechIn1 = [silence;speechIn];
If silence and speechIn have different sizes, then this works only if they are both column vectors. Not sure if they are passed in as row vectors from C# - you could try adding the following lines to the top of the MATLAB function, recompile, and try this again:
% Convert silence and speechIn to column vectors
silence = reshape(silence, [numel(silence) 1]);
speechIn = reshape(speechIn, [numel(speechIn) 1]);

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Deploy to .NET Applications Using MWArray API 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by