is it possible to use the syntax V(i) as a vector?

9 ビュー (過去 30 日間)
Mr M.
Mr M. 2014 年 12 月 5 日
回答済み: 埃博拉酱 2024 年 10 月 26 日 15:11
I've got a function which has collection of vectors with the same length as an output. Is it possible to somehow make this collection such that users can use the syntax V(i) for reaching the ith vector from the collection, where V = myfunc() is the output of my function. It is possible to use matrices or cell arrays to create the collection, but in these cases users have to use the syntax V(i,:) or V{i}. I would like to use V(i)!
  1 件のコメント
dpb
dpb 2014 年 12 月 5 日
A singleton address into a vector is unilaterally a single element of that vector; anything else would break too much. OTOMH the cell array is as close as you can get...

サインインしてコメントする。

回答 (1 件)

埃博拉酱
埃博拉酱 2024 年 10 月 26 日 15:11
The simplest method is to return a function handle:
function V=myfunc()
V=rand(3);
V=@(i)V(i,:);
end

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by