Home > Blockchain >  MATLAB fails to display plot, but Microsoft Excel can
MATLAB fails to display plot, but Microsoft Excel can

Time:10-21

My goal is to recreate a plot in Excel in MATLAB. In excel, I have coded:

1/(1   (SINH($B$4^(1/2)*(1 - C6)^(1/2)))^2/(4*C6*(1-C6)))

In the above, cell B4 has the value 10. C6 through C500 take values starting at 0 upto 5 in succession (so C6 would be 0, and C500 would be C6 0.01 0.01 0.01... = 5), with increments of 0.01.

In other words, the column 'C' runs from 0 to 5 in increments of 0.01 (which is the x axis of the plot). I then apply the above formula to column C to obtain the graph below.

Excel displays the following, which is correct: Excel Graph of Equation Above

However, attempting to recreate the same graph in MATLAB results in an empty plot (which I show after the code)

 v = 10
 x = [0:0.01:5]
 plot(x, 1/(1   (sinh(v^(1/2)*(1 - x).^(1/2))).^2/(4*x.*(1-x))), 'LineWidth', 2)

 grid on
 xlabel('x')
 ylabel('Transmittance')

MATLAB Problem

I have tried restarting my computer, restarting MATLAB to no avail. Thanks for your guidance!

CodePudding user response:

You forgot two .'s:

1./(1   (sinh(v^(1/2)*(1 - x).^(1/2))).^2./(4*x.*(1-x)))
 ^                                       ^

I advise you to first evaluate the expression and store in a varable, then you can immediately see that without this dot you will a single value. Plotting a vector and a single value doesn't really produce anything usable, but also does not throw an error, so it's tricky to debug without having the variable in the workspace.

  • Related