Avoide imaginary part in cell matrix

Hi all
i have a cell matrix A like that:
val(:,:,1,1,1) =
Columns 1 through 10
{n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double}
Columns 11 through 20
{n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double} {n×2 double}........
i want to obtain another cell matrix with the same global dimension of the previous one but with only the first column values: so i want to obtain a matrix where each cell has dimension equal to {nx1} . I also want to estrapolate from A only those cells that contain elements with imaginary part less than 0.1 setting to zero all the cells that don't satisfy this condition. Is there an easy way for doing that?
Thank you for the help
Regards

 採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
編集済み: Ameer Hamza 2020 年 10 月 13 日

0 投票

Here is the solution to the first part
A; % 1x20 cell array
A_new = cellfun(@(x) {x(:,1)}, A);
All cell in A_new will contain first column of matrices in A.
I didn't understand the 2nd question related to setting the imaginary part to zero.

7 件のコメント

EldaEbrithil
EldaEbrithil 2020 年 10 月 13 日
Thank you very much Ameer!!
The 2nd question refers to the filtering of those columns that contain elements with an imaginary part less than 0.1: i want only those columns, the other columns must be set equal to zero
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
The cell array in your question only contains double values? Is the real matrix different than the one you pasted in the question?
EldaEbrithil
EldaEbrithil 2020 年 10 月 13 日
編集済み: EldaEbrithil 2020 年 10 月 13 日
yes it contains only double values
no it is a 5th dimension matrix, i had only published an exctract of the matrix
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
So, where do the complex values exist? Or does the first column contain the real part, and the 2nd column contains the complex part?
Ameer Hamza
Ameer Hamza 2020 年 10 月 13 日
編集済み: Ameer Hamza 2020 年 10 月 13 日
If 2nd columns contain the imaginary part, then you can try following command
A_new = cellfun(@(x) {x(:,1).*(x(:,2)<0.1)}, A);
EldaEbrithil
EldaEbrithil 2020 年 10 月 13 日
The first and the second column contain complex values. I would like to perform the following operations in order:
  • stay with one column instead of two
  • take those cells (made up of only one column each) that respect that condition on the imaginary part
Ameer Hamza
Ameer Hamza 2020 年 10 月 14 日
Ok. Following should work in this case
A; % 1x20 cell array
A_new1 = cellfun(@(x) {x(:,1)}, A); % only contain 1st columns
A_new2 = cellfun(@(x) {x.*(imag(x)<0.1)}, A_new1); % set the rows which does not satisfy the imaginary number conditions to 0.

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeNumeric Types についてさらに検索

質問済み:

2020 年 10 月 13 日

コメント済み:

2020 年 10 月 14 日

Community Treasure Hunt

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

Start Hunting!

Translated by