How can i extract the values in complex double array

14 次查看(过去 30 天)
I have the below complex double array, when i want to extract the fourth value and the ones which are above of the fourth one (like H(5) H(6) H(7) ....) Matlab says " All zero sparse: 1×1". so How can i extract them ?
H=
(1,1) -0.0181 - 0.0365i
(2,1) 0.2017 - 0.0552i
(3,1) 0.0795 - 0.0786i
(2,2) -0.0173 - 0.0370i
(3,2) 0.2023 - 0.0551i
(4,2) 0.0794 - 0.0785i
(3,3) -0.0166 - 0.0374i
(4,3) 0.2028 - 0.0551i
(5,3) 0.0793 - 0.0785i
(4,4) -0.0158 - 0.0378i
(5,4) 0.2034 - 0.0550i
(6,4) 0.0793 - 0.0784i
(5,5) -0.0151 - 0.0383i
(6,5) 0.2040 - 0.0549i
  2 个评论
James Tursa
James Tursa 2023-8-30
Do you mean extract the fourth non-zero value? In memory order? Please post an example input and exact output you want.
Mathieu NOE
Mathieu NOE 2023-8-30
hello
according to your post H would be a 2D and not 1D arry so when you say the fourth and above index is fine for a 1D array but I don't know what you need to extract for a 2D array
H(1,1) = -0.0181 - 0.0365i;
H(2,1) = 0.2017 - 0.0552i;
H(3,1) = 0.0795 - 0.0786i;
H(2,2) = -0.0173 - 0.0370i;
H(3,2) = 0.2023 - 0.0551i;
H(4,2) = 0.0794 - 0.0785i;
H(3,3) = -0.0166 - 0.0374i;
H(4,3) = 0.2028 - 0.0551i;
H(5,3) = 0.0793 - 0.0785i;
H(4,4) = -0.0158 - 0.0378i;
H(5,4) = 0.2034 - 0.0550i;
H(6,4) = 0.0793 - 0.0784i;
H(5,5) = -0.0151 - 0.0383i;
H(6,5) = 0.2040 - 0.0549i;
imagesc(abs(H));colorbar('vert')

请先登录,再进行评论。

回答(1 个)

MYBLOG
MYBLOG 2023-8-30
You can achieve this using logical indexing and comparison of the magnitudes of the complex values. Here's how you can extract the fourth value and the values above it in MATLAB:
% Given complex array H
H = [
-0.0181 - 0.0365i
0.2017 - 0.0552i
0.0795 - 0.0786i
-0.0173 - 0.0370i
0.2023 - 0.0551i
0.0794 - 0.0785i
-0.0166 - 0.0374i
0.2028 - 0.0551i
0.0793 - 0.0785i
-0.0158 - 0.0378i
0.2034 - 0.0550i
0.0793 - 0.0784i
-0.0151 - 0.0383i
0.2040 - 0.0549i
];
% Extract the fourth value
fourth_value = H(4);
% Find the indices of values above the fourth value
above_fourth_indices = abs(H) > abs(fourth_value);
% Extract the values above the fourth value
values_above_fourth = H(above_fourth_indices);
% Display the results
disp('Fourth Value:');
disp(fourth_value);
disp('Values Above Fourth Value:');
disp(values_above_fourth);

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by