I want to index a element of a vector after defining it
3 次查看(过去 30 天)
显示 更早的评论
I want to select the first element of a vector without having to store it in a variable. For example, if i want to know the smallest prime divider of a number, i want to write this
factor(56)(1)
However this is invalid. Any correct way to do this?
0 个评论
采纳的回答
Stephen23
2024-10-7
移动:Rik
2024-10-7
"Any correct way to do this?"
Yes, but only if you want to make your code complex, awkward, and obfuscated:
subsref(factor(56),substruct('()',{1}))
struct('x',factor(56)).x(1)
The MATLAB approach: store it in a vector. Note that how many lines you use is not an indicator of runtime efficiency.
更多回答(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!