Yes. There is a difference, and a fundamental one. In the first case, the assignment a=b COMPLETELY replaces a. The variable is overwritten, if it already exists. If not, a new variable is created with that name. What a was before is completely irrelevant. Even the class of a is replaced. For example:
whos a b
Name Size Bytes Class Attributes
a 1x3 3 uint8
b 1x4 32 double
As you can see, the two variables are not even the same classes. But now when we use a = b, a has been replaced. It has a new size. And a is now double precision.
a = b
a =
0.0366 0.9518 0.5077 0.6811
whos a b
Name Size Bytes Class Attributes
a 1x4 32 double
b 1x4 32 double
Now, lets try the second example, where we use indexing.
b = rand(1,4)
b =
0.3677 0.6780 0.7891 0.8548
Now use indexing:
whos a b
Name Size Bytes Class Attributes
a 1x4 4 uint8
b 1x4 32 double
Here, elements of a are now selectively replaced with elements of b. But now there is a class conversion that happens first. Here the elements of a are still uint8, so a round was performed to convert elements of b into elements of a.
Is one operation faster than the other? The index operation must certainly be slower. But this is not a slow thing. So I'll put the operations into a function, then use timeit.
timeit(@() speedtest1(a,b))
timeit(@() speedtest2(a,b))
So, where there was a class conversion, speedtest1 is way faster. In the next test, there will be no class conversion.
timeit(@() speedtest1(a,b))
timeit(@() speedtest2(a,b))
So here the replacement was way faster. In both cases, when you do an insert of selected elements, MATLAB spends a lot of time, first, generating the index vector. Then it needs to overwrite those selected elements, making sure any class conversion is done if needed.
function a = speedtest1(a,b)
function a = speedtest2(a,b)
So, is there a difference? Yes. There must be one.