user-1: 
I am trying to send some integers to an LCD. But it is not working. I have tried in Proteus. Please help. I have uploaded MATLAB and Arduino code below.
MATLAB code:
clear all
clc

 answer=1; % this is where we'll store the user's answer
 arduino=serial('COM1','BaudRate',9600); % create serial communication object on port COM4

fopen(arduino); % initiate arduino communication

while answer
fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); % ask user to enter value for variable answer
end

fclose(arduino); % end communication with arduino

Arduino code:
#include <LiquidCrystal.h>
int matlabData;
LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {
  lcd.begin(16,2);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()>0) {
    matlabData=Serial.read();
    lcd.print(matlabData);
  }
}


user29295: You can use Matlab's Arduino support package, it allows you to control the Arduino directly without having to write code in the Arduino IDE. I never used it with an LCD though. Here is a link that might help.

user4628: while answer
  fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
  answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): ');
  % ask user to enter value for variable answer
end

Is it just me or should asking the user to input something be before printing it?
Also, more importantly, isn't fprintf(arduino, '%s', char(answer)); printing raw bytes? In which case, you would be sending 0x01/0x02. Not a great idea... In your Arduino code, print out on Serial what you are receiving, in [hexa]decimal, not as char.
    matlabData=Serial.read();
    Serial.print("Received: [0x");
    if(matlabData<16)Serial.write('0');
    Serial.print(matlabData, HEX);
    Serial.println("]");

This should give you a better idea whether you received anything, and if so, what.

-1: <p><a href="https://i.stack.imgur.com/PluwX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PluwX.png" alt="enter image description here"></a></p>

<p>I am trying to send some integers to an LCD. But it is not working. I have tried in Proteus. Please help. I have uploaded MATLAB and Arduino code below.</p>

<p>MATLAB code:</p>

<pre><code>clear all
clc

 answer=1; % this is where we'll store the user's answer
 arduino=serial('COM1','BaudRate',9600); % create serial communication object on port COM4

fopen(arduino); % initiate arduino communication

while answer
fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): '); % ask user to enter value for variable answer
end

fclose(arduino); % end communication with arduino
</code></pre>

<p>Arduino code:</p>

<pre><code>#include &lt;LiquidCrystal.h&gt;
int matlabData;
LiquidCrystal lcd(12,11,5,4,3,2);

void setup() {
  lcd.begin(16,2);
  Serial.begin(9600);
}

void loop() {
  if(Serial.available()&gt;0) {
    matlabData=Serial.read();
    lcd.print(matlabData);
  }
}
</code></pre>
 29295: <p>You can use Matlab's Arduino support package, it allows you to control the Arduino directly without having to write code in the Arduino IDE. I never used it with an LCD though. Here is <a href="https://www.mathworks.com/hardware-support/arduino-matlab.html" rel="nofollow noreferrer">a link</a> that might help.</p>
 4628: <pre><code>while answer
  fprintf(arduino,'%s',char(answer)); % send answer variable content to arduino
  answer=input('Enter led value 1 or 2 (1=ON, 2=OFF, 0=EXIT PROGRAM): ');
  % ask user to enter value for variable answer
end
</code></pre>

<p>Is it just me or should asking the user to input something be <strong><em>before</em></strong> printing it?</p>

<p>Also, more importantly, isn't <code>fprintf(arduino, '%s', char(answer));</code> printing raw bytes? In which case, you would be sending 0x01/0x02. Not a great idea... In your Arduino code, print out on Serial what you are receiving, in [hexa]decimal, not as <code>char</code>.</p>

<pre><code>    matlabData=Serial.read();
    Serial.print("Received: [0x");
    if(matlabData&lt;16)Serial.write('0');
    Serial.print(matlabData, HEX);
    Serial.println("]");
</code></pre>

<p>This should give you a better idea whether you received anything, and if so, what.</p>
