Extracting a vector from elements of a matrices that are in a cell structure.

1 回表示 (過去 30 日間)
Hi,
I have written this simple program:
C = {[1,2],[3,4],[5,6]},C{1},C{2},C{3},V=[C{1}(1),C{2}(1),C{3}(1)],V2=[C{1}(2),C{2}(2),C{3}(2)],
and the answer is V1=[1,3,5],V2=[1,3,5].
But if I write in a compact way, let us say:
V=[C{1:3}(1)]
it doesn't work. The result is:
"Expected one output from a curly brace or dot indexing expression, but there were 3 results."
How to fix it?
Thanks!.
  2 件のコメント
Image Analyst
Image Analyst 2020 年 2 月 22 日
What is your desired output? [1;3;5]?
Vicente Casares-Giner
Vicente Casares-Giner 2020 年 2 月 22 日
Some wrong information was written in my previous e-mail, sorry.
It should be V(or V1)=[1,3,5],V2=[2,4,5].
How to write in a simple sentence without the use of "for ---- end"?

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

採用された回答

Andrei Bobrov
Andrei Bobrov 2020 年 2 月 22 日
編集済み: Andrei Bobrov 2020 年 2 月 22 日
V = cat(1,C{:});
V(:,1)'
V(:,2)'

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by