The value assigned to variable <variable_name> might be unused

please can any one solve these errors of some lines that have red underline because i am novice in matlab and i don't know the basics
here the code :
all of these lines have the same M-Lint warning "The value assigned to variable variable_name might be unused"
>> variable name which has red underline
thank you

回答(3 个)

On lines 4 and 7, add the comment
%#OK
at the end of the line.
Change line 12 to
fclose(Fid);
rather than being an assignment.

7 个评论

ya thank you Mr. i did and it is ok , but i link this code with vb.net so when i call it in vb this message appear
maybe because of M-lint warning at line 24,26 but also when i add %#OK at the end of all warning line even line 24,26 , the message still appear so please please help me as soon as possible :(
How is this question different than http://www.mathworks.com/matlabcentral/answers/110597-error-unexpected-matlab-operator where Walter and I already started helping you on this question? Why start all over again?
Unused variables are just a warning and do not cause that message box.
Please post father.wav, your m-file, and path1.txt so someone with the appropriate toolboxes (which you still need to list in the Products box under your question) can run your code. For example, what toolbox is melcepst() in?
the toolbox is voicebox , you mean i have to add these files in voicebox toolbox folder ?
No, you should not add your files to the voicebox toolbox folders.
What you should do, though, is what I indicated in your simultaneous thread on this topic: show us how you invoked the code from vb.net
That's not a Mathworks toolbox, and since probably not many people have it, you may not have a lot of people able to help you. Does your code run if you call it from a different m-file that supplies the same input arguments as you do when you call it from VB?
the code is run in matlab without error ,only M-lint warning >> test2
ans =
false
and in vb when i call it appear that error message box
and this is how i invoke this matlab code in vb :
Module Module2
Sub main()
Dim MatLab As Object
Dim Result As String
MatLab = CreateObject("Matlab.Application")
MatLab.Execute("enableservice('automationserver',true)")
MatLab.Visible = False
Result = MatLab.Execute("cd D:\university\sem9\voicebox toolbox")
Result = MatLab.Execute("voicebox")
Result = MatLab.Execute("C:\Users\TOSHIBA\test2")
MsgBox(Result)
If Result.Contains("true") Then
My.Computer.Audio.Play("C:\Users\TOSHIBA\clapping.wav", AudioPlayMode.Background)
Else : My.Computer.Audio.Play("C:\Users\TOSHIBA\wrong.wav", AudioPlayMode.Background)
End If
End Sub
End Module
This is the code of record in vb :
Public Class father
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Button1.Enabled = False
Button2.Enabled = True
mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
mciSendString("record recsound", "", 0, 0)
End Sub
Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Button1.Enabled = True
Button2.Enabled = False
Button3.Enabled = True
mciSendString("save recsound C:\Users\TOSHIBA\nnn.wav", "", 0, 0) ' recordrd file path
mciSendString("close recsound", "", 0, 0)
Dim File_name_a As String = "C:\Users\TOSHIBA\path1.txt"
Dim objwriter As New System.IO.StreamWriter(File_name_a)
objwriter.WriteLine("1")
objwriter.Write("C:\Users\TOSHIBA\nnn.wav")
objwriter.Close()
MessageBox.Show("your voice is recorded")
main()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
My.Computer.Audio.Play("C:\Users\TOSHIBA\nnn.wav", AudioPlayMode.Background)
End Sub
Spaces may be messing you up. MATLAB may be interpreting it as two different strings unless you wrap in single quotes. So instead of this:
Result = MatLab.Execute("cd D:\university\sem9\voicebox toolbox")
try this:
Result = MatLab.Execute("cd 'D:/university/sem9/voicebox toolbox'")
Also try forward slashes, which MATLAB and Windows are just fine with:
Result = MatLab.Execute("C:/Users/TOSHIBA/test2.m")
just in case it's using the backslash to indicate a special character like \t or \n.

请先登录,再进行评论。

C:\Users\TOSHIBA\test2
is not a valid MATLAB command.
Use addpath() to add C:\Users\TOSHIBA to your MATLAB path, and then use
test2
Alternately, code
Result = MatLab.Execute("run('C:\Users\TOSHIBA\test2.m')")

3 个评论

Use addpath() to add C:\Users\TOSHIBA to your MATLAB path, and then use test2
^
Do you mean i have to do that !!
i did it
----------
when i put this line Result = MatLab.Execute("run('C:\Users\TOSHIBA\test2.m')") the run output of matlab code in matlab "which is sound" , is appear in vb but still the error message box appearing so what can i do !
thank you mr. for your attention
i am waiting for you please :( really sorry but because i have to submit the project at the end of this week :(
sorry again
Result = MatLab.Execute("addpath('C:\Users\TOSHIBA');")
Result = MatLab.Execute("test2");

请先登录,再进行评论。

n
n 2013-12-28
编辑:n 2013-12-28
it is ok so so thanks Mr and the error doesn't not appear now but appear this voicebox parameters message , i don't know what is it !
second this matlab code is about speech recognition that compares two sound one of them stord sound in database and the second is recorded sound and then returns as result "matching" or a "not matching
when matching , clapping.wav is run
when not matching , wrong.wav is run
as it written in vb code which invoke matlab code
the problem here that the wrong.wav always run in vb although the recorded word is right
even in matlab when i calling test2 the ans is false not true
>> test2
ans =
false
so what is the problem please here is the matlab code do comparing correctly!! because it runs strange sound not the record sound so please can you see what is the problem here
1. what is voicebox parameters msg ?? 2. why the vb run wrong.wav or in matlab " ans = false "??
thank you so much for your cooperation and attention and really sorry :(

11 个评论

You are comparing the result to the string "true", but MATLAB is returning numeric true, which is probably coming through as 1 (and 0 for false)
ok now i changed result to integer but this warning is appear and see under the code in "Autos part" the Result in matlab is 0
please what is the problem here or maybe my correction is wrong :(
I am not familiar with Visual Basic. Have you considered altering your MATLAB code to return a string instead of a logical value ?
Try
Dim Result as String
and see what that does. Then you might have to change your if to
if Results = "1" then
Mr.Walter Roberson how i can do that ? and what is the variable i have to change it ? Mr.Image Analyst i did that and appear voicebox parameters msg again and still ans = false :( is my matlab code comparing sounds correctly ? :(
I told you how to change Result to a string like Walter suggested. I don't see any "i" variable so I don't know what you're talking about. Can you put a message box in test2.m as the first line and have it say
uiwait(msgbox('Starting to run test2 now'));
so we can see if test2 is actually being run?
I put it like this
and the code is run and msgbox appear and ans= true
then when I run vb still voicebox parameters appear and reply "wrong.wav"
------
"I don't see any "i" variable so I don't know what you're talking about"
^
sorry I mean by i = I "me", not variable named i
I mean what is the variable in matlab I have to change not the "Result" variable in vb because he told me that "altering your MATLAB code to return a string instead of a logical value " .
I try to use Dynamic Time Warping algorithm , maybe the comparing not match because of warped record sound so please where i can put the calling of Dynamic Time Warping function after which line ???
this is the calling of algorithm
[Dist,D,k,w]=dtw(A,path); %#ok
and this is the code :
function test =test2()
uiwait(msgbox('Starting to run test2 now'));
clear;
[x,f]=audioread('C:\Users\TOSHIBA\father.wav');
extract=melcepst(x,f);%#ok
save( 'C:\Users\TOSHIBA\father.mat','extract');
[x1,f1]=audioread('C:\Users\TOSHIBA\color.wav');
extract2=melcepst(x1,f1); %#ok
save( 'C:\Users\TOSHIBA\color.mat','extract2');
Fid=fopen('C:\Users\TOSHIBA\path1.txt');
A=fscanf(Fid,'%u');
path=fscanf(Fid,'%s');
fclose(Fid);
[x,fsampling]=audioread(path);
pause(5);
x=fft(x);
fp=100;
fs=1000;
wp=2*fp/fsampling;
ws=2*fs/fsampling;
[N,wn]=buttord(wp,ws,1,5);
[b,a]=butter(N,wn);
y=filter(b,a,x);
soundsc((real(double(y))),fsampling)
[h,t]=impz(b,a);%#ok
N1=size(h,1);
n=1:N1;%#ok
extract=melcepst(y,fsampling);
if(A==1)
B1=importdata('C:\Users\TOSHIBA\father.mat');
d1=disteusq(extract,B1);
result1=int64(sum(sum(d1)));
if ((result1>=1517405)&&(result1<=3399480))
test='true';
else test='false';
end
end
if(A==2)
B2=importdata('C:\Users\TOSHIBA\color.mat');
d2=disteusq(extract,B2);
result2=int64(sum(sum(d2)));
if ((result2>=521370)&&(result2<=668471))
test='true';
else test='false';
end
end
please help me :'( my teachers want the project this time and i am very depressed
Neither Image Analyst nor I have experience with that kind of audio work.
Have you now isolated the problem as being with your signal-processing and not with the VB to MATLAB interface? If so then it would be time to open a new third Question for the signal processing part.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

标签

提问:

n
n
2013-12-25

Community Treasure Hunt

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

Start Hunting!

Translated by