user4090: I am new to Arduino and I am trying to control it through MATLAB.  I have downloaded the arduino IO package and installed it.I am using MATLAB 2014a.I have a LED and I change its brightness by changing the PWM voltage as follows :
a=arduino('COM3');
brightness_step = (5-0)/20;
   for i = 1:20
      writePWMVoltage(a, 11, i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end

   for i = 1:20
      writePWMVoltage(a, 11, 5-i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end
clear a

Everything works great except for the analogRead part which throws the following error :
No appropriate method, property, or field analogRead for class arduino.
What am I doing wrong?

user11763: That function is part of legacy code. 

NOTE: This solution (formerly known as "Arduino IO Package") is no
  longer supported. It is recommended that you use Arduino support
  packages that are developed and supported by MathWorks:

MATLAB Support Package for Arduino Hardware: Read, write, and analyze data from Arduino sensors 
  http://www.mathworks.com/hardware-support/arduino-matlab.html
Simulink Support Package for Arduino Hardware: Develop algorithms that run standalone on your Arduino 
  http://www.mathworks.com/hardware-support/arduino-simulink.html

Use this legacy support only if one of the following is true: 
- You are using MATLAB R2013b or earlier (but not earlier than R2011a).

You are using 2014a, so its probably the reason analogRead isn't working. Get the more recent package and use this function instead:


4090: <p>I am new to Arduino and I am trying to control it through MATLAB.  I have downloaded the arduino IO package and installed it.I am using MATLAB 2014a.I have a LED and I change its brightness by changing the PWM voltage as follows :</p>

<pre><code>a=arduino('COM3');
brightness_step = (5-0)/20;
   for i = 1:20
      writePWMVoltage(a, 11, i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end

   for i = 1:20
      writePWMVoltage(a, 11, 5-i*brightness_step);
      val=a.analogRead(0);
      display(val)
      pause(0.1);
   end
clear a
</code></pre>

<p>Everything works great except for the analogRead part which throws the following error :
<strong>No appropriate method, property, or field analogRead for class arduino.</strong></p>

<p>What am I doing wrong?</p>
 11763: <p>That function is part of legacy code. </p>

<blockquote>
  <p>NOTE: This solution (formerly known as "Arduino IO Package") is no
  longer supported. It is recommended that you use Arduino support
  packages that are developed and supported by MathWorks:</p>
  
  <ul>
  <li><p>MATLAB Support Package for Arduino Hardware: Read, write, and analyze data from Arduino sensors 
  <a href="http://www.mathworks.com/hardware-support/arduino-matlab.html" rel="nofollow noreferrer">http://www.mathworks.com/hardware-support/arduino-matlab.html</a></p></li>
  <li><p>Simulink Support Package for Arduino Hardware: Develop algorithms that run standalone on your Arduino 
  <a href="http://www.mathworks.com/hardware-support/arduino-simulink.html" rel="nofollow noreferrer">http://www.mathworks.com/hardware-support/arduino-simulink.html</a></p></li>
  </ul>
  
  <p>Use this legacy support only if one of the following is true: </p>
  
  <p><strong>- You are using MATLAB R2013b or earlier (but not earlier than R2011a).</strong></p>
</blockquote>

<p>You are using 2014a, so its probably the reason <code>analogRead</code> isn't working. Get the more recent package and use this function instead:</p>

<p><a href="https://i.stack.imgur.com/tRM9A.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tRM9A.png" alt="MATLAB + Arduino"></a></p>
