linspace returning 1 value

Tmax = 1000;
Tc = linspace(487.87,Tmax)
when running the script, Tc is set to just the Tmax value but should be returning 100 evenly spaced values.

回答(1 个)

You need to give linspace() the number of points, like
Tmin = 487.87;
Tmax = 1000;
numPoints = 100;
Tc = linspace(Tmin, Tmax, numPoints)

4 个评论

Tcompressor1 = 487.85;
nums = 100;
Tmax = 1000;
Tcombustor = linspace(Tcompressor1,Tmax,nums)
Tcombustor = 1×100
487.8500 493.0232 498.1965 503.3697 508.5429 513.7162 518.8894 524.0626 529.2359 534.4091 539.5823 544.7556 549.9288 555.1020 560.2753 565.4485 570.6217 575.7949 580.9682 586.1414 591.3146 596.4879 601.6611 606.8343 612.0076 617.1808 622.3540 627.5273 632.7005 637.8737
Rewrote to this and still returned the Tmax value;
How is that possible?
Tcompressor1 = 487.85;
nums = 100;
Tmax = 1000;
Tcombustor = linspace(Tcompressor1,Tmax,nums)
Tcombustor = 1×100
487.8500 493.0232 498.1965 503.3697 508.5429 513.7162 518.8894 524.0626 529.2359 534.4091 539.5823 544.7556 549.9288 555.1020 560.2753 565.4485 570.6217 575.7949 580.9682 586.1414 591.3146 596.4879 601.6611 606.8343 612.0076 617.1808 622.3540 627.5273 632.7005 637.8737
As you can see, it returns 100 values, not just the single Tmax value.
I don't know. I copy and pasted the code into a new script and it worked now. Thanks for the help.
Maybe you forgot to click the run button. If you do, it will run identically each and every time. I've be extremely surprised if that same code ran one way in your old script and another way in your new script, my computer, and in MATLAB online.
So, since it's solved, can you click the "Accept this answer" link? Thanks in advance.

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 Matrix Indexing 的更多信息

产品

版本

R2020b

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by