フィルターのクリア

Extract specific rows of a cell

19 ビュー (過去 30 日間)
Majid Mostafavi
Majid Mostafavi 2020 年 1 月 25 日
編集済み: Akira Agata 2020 年 1 月 25 日
Hey everyone
I have a cell A as below and want to extract a matrix form A of specific rows which stored at r from each rows of A for example row number 4 from first row of A and ...
A= { 90×1 double} { 90×1 double} { 90×1 double}
{101×1 double} {101×1 double} {101×1 double}
{101×1 double} {101×1 double} {101×1 double}
{100×1 double} {100×1 double} {100×1 double}
{ 97×1 double} { 97×1 double} { 97×1 double}
{ 75×1 double} { 75×1 double} { 75×1 double}
r=
4
6
99
43
68
50
  2 件のコメント
Akira Agata
Akira Agata 2020 年 1 月 25 日
Question for clarification.
Is the cell array A a 2-D (N-by-M) ? or 1-D (1-by-N or N-by-1) ?
If A is a 1-D cell array, you want to extract k-th number from each double array stored in a cell?
For example, if r = 4, you want to extract A{1}(4), A{2}(4), ..., A{N}(4) and make a 1-D double array [A{1}(4), A{2}(4), ..., A{N}(4)] ?
Majid Mostafavi
Majid Mostafavi 2020 年 1 月 25 日
yes
but A{2}(4) give me only second element of first column

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

回答 (1 件)

Akira Agata
Akira Agata 2020 年 1 月 25 日
編集済み: Akira Agata 2020 年 1 月 25 日
OK. Then, to avoid misunderstanding, let's use a simple example.
Say, A is a 1-by-3 cell array and r = 4, as follows:
A = {rand(90,1), rand(101,1), rand(100,1)};
r = 4;
If you write [A{1}(r), A{2}(r), A{3}(r)], then you can extract the 4th element of each cell.
output = [A{1}(r), A{2}(r), A{3}(r)];
But if A is large array, such as 1-by-10000, it's impossible to use the above solution.
In such a case, I would recommend using cellfun function to do the same thing, like this:
output = cellfun(@(x) x(r), A);
I hope this is answering to your question!

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by