generating an equispaced vector using a variable
1 次查看(过去 30 天)
显示 更早的评论
Hi, I have a variable that I want to use to make each variable in part of a vector equi-spaced, and I cannot figure out why it is not working. In the code below it works for variable "a" but not "aNumber", I'm sure this is obvious but I cannot see it. Does anyone know why Matlab is treating "a" differently from "aNumber"?
B=nan(57,5)
aNumber=1.111
a=1
B(1:50,1)=(1:50)
B(1:50,2)=(1:1:50)
B(1:50,3)=(a:1:a*50)
B(1:50,4)=(a:a*50)
B(1:50,5)=(aNumber : aNumber*50)
gives...
Subscripted assignment dimension mismatch.
Error in untitled36 (line 25)
B(1:50,5)=(aNumber : aNumber*50)
Best regards,
Steve
5 个评论
采纳的回答
KSSV
2018-3-15
This would be more apt:
B(1:50,5)=linspace(aNumber , aNumber*50,50)
then
B(1:50,5)=(aNumber : aNumber*50)
Your line creates 1X55 vector, so the error...you actually need 1x50 vector.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!