'Matlab, Plot/Graph Changes when the Line Style Changes

I am using Matlab ver R2017A. When I plot the following code below, I get a sine wave as expected using the default line style.

x = linspace(0,10);
h1 = sin(x);
plot([x,h1],'--')
legend('Location','southwest')

However, when I add a different line style, the plot goes all wonky. From a sine wave, it changes to some half triangular wave followed by very small sine waves, with of course using a dashed line style.

x = linspace(0,10);
h1 = sin(x);
plot([x,h1],'--')
legend('Location','southwest')

I then tried the following, but now the plot/graph completely disappeared from the figure. All I see are the X and Y axes:

plot(x,h1,"LineStyle",'--');

Any ideas why this is happening and how to correct it?



Solution 1:[1]

Oh forget it. I fixed the issue. I needed to remove the square brackets. I assumed the R2022 syntax was the same as documented in R2017A. By default, a search on google will bring you to the latest version of the documentation. I decided to search R2017A and there it was; no square brackets. The latest Matlab documentation would normally mention changes to the syntax from previous version, but in this case it did not.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 GusG