MATLAB Answers


The value assigned to variable <variable_name> might be unused

Asked by n
on 25 Dec 2013
Latest activity Commented on by Walter Roberson
on 29 Dec 2013

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

  1 Comment

Please post your code as a text not as an image.

Log in to comment.



No products are associated with this question.

3 Answers

Answer by Walter Roberson
on 25 Dec 2013

On lines 4 and 7, add the comment


at the end of the line.

Change line 12 to


rather than being an assignment.


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 =


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.Visible = False
        Result = MatLab.Execute("cd D:\university\sem9\voicebox toolbox")
        Result = MatLab.Execute("voicebox")
        Result = MatLab.Execute("C:\Users\TOSHIBA\test2")
        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)
        MessageBox.Show("your voice is recorded")
    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.

Log in to comment.

Answer by Walter Roberson
on 27 Dec 2013


is not a valid MATLAB command.

Use addpath() to add C:\Users\TOSHIBA to your MATLAB path, and then use


Alternately, code

Result = MatLab.Execute("run('C:\Users\TOSHIBA\test2.m')")


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");

Log in to comment.

Answer by n
on 28 Dec 2013
Edited by n
on 28 Dec 2013

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 =


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 :(


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'));
save( 'C:\Users\TOSHIBA\father.mat','extract');
extract2=melcepst(x1,f1); %#ok
save( 'C:\Users\TOSHIBA\color.mat','extract2');
if ((result1>=1517405)&&(result1<=3399480))
else test='false';
if ((result2>=521370)&&(result2<=668471))
else test='false';

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.

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!