How to convert from decimal to binary in matlab.....this is what I have so far.....

dec = 43;
i = 1;
sum=0;
while dec>0
r = rem(dec, 2);
sum=sum+(i*rem);
dec=dec/2;
i=i*10;
end
sum

The logic looks correct except for one minor logic error in:

sum=sum+(i*rem);
which should read
sum=sum+i*r;

You need to make sure the statements execute correctly in Matlab syntax.
For example, an integer division can be written as
dec=dec./2;
or
dec=idivide(dec,2);

Also, be careful about overflow of the decimal representation of the binary number (sum), which has at least 3 times more digits as the decimal equivalent.

To convert a decimal number to binary in MATLAB, you can use the following steps:

1. Assign the decimal number you want to convert to a variable, let's say `dec`. For example, `dec = 43;`.
2. Initialize a variable to keep track of the binary number, let's call it `binary`. Set it to an empty array. For example, `binary = [];`.
3. Use a while loop to perform the conversion until the decimal number becomes zero. Inside the loop:
a. Calculate the remainder of `dec` divided by 2 using the `rem()` function. Assign this remainder to a variable, let's call it `r`.
b. Update the value of `dec` by dividing it by 2 using the `/` operator. This will discard the remainder.
c. Append the value of `r` to the beginning of the `binary` array using the `[r binary]` syntax. This will build the binary number from right to left.
4. After the loop ends, the `binary` array will contain the binary representation of the decimal number. You can display it or use it for further computations.

Here's an example implementation of the above steps:

```matlab
dec = 43;
binary = [];

while dec > 0
r = rem(dec, 2);
binary = [r binary];
dec = dec / 2;
end

binary
```

Running this code will output the binary representation of the decimal number 43, which is `[1 0 1 0 1 1]`.