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

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

Azzi Abdelmalek on 25 Dec 2013

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

n

Tags

Products

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

%#OK

at the end of the line.

Change line 12 to

fclose(Fid);

rather than being an assignment.

7 Comments

Image Analyst on 27 Dec 2013

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?

n on 27 Dec 2013

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
Image Analyst on 27 Dec 2013

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.

Walter Roberson
Answer by Walter Roberson on 27 Dec 2013
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 Comments

n on 27 Dec 2013
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

n on 27 Dec 2013

i am waiting for you please :( really sorry but because i have to submit the project at the end of this week :(

sorry again

Walter Roberson on 27 Dec 2013
Result = MatLab.Execute("addpath('C:\Users\TOSHIBA');")
Result = MatLab.Execute("test2");
Walter Roberson
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 =

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 Comments

n on 29 Dec 2013

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
n on 29 Dec 2013

please help me :'( my teachers want the project this time and i am very depressed

Walter Roberson on 29 Dec 2013

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.

n

Contact us