How to extract values from columns in a matrix

4 ビュー (過去 30 日間)
Afluo Raoual
Afluo Raoual 2021 年 2 月 8 日
コメント済み: acun67 acu 2021 年 2 月 9 日
Dear members
I have this matrix (5*5) for example
H=[0 0 0 0 0;
0 1 0 0 0;
1 1 0 0 0;
1 0 1 0 0;
1 0 1 1 0]
I want to extract from each column, the corresponding value.
It means:
  • from the first column, I want the first value. (which is 0)
  • from the second column, I want the second value. (which is 1)
  • from the third column, I want the third value. (which is 0)
  • ........... etc
until the last column, I want the last value.
Please, how can I program this in MATLAB, especially that I want a general program for any matrix. Not specifically for this matrix.
Thank you.

採用された回答

Jan
Jan 2021 年 2 月 8 日
編集済み: Jan 2021 年 2 月 8 日
H=[2 0 0 0 0; % Smarter test data with
0 3 0 0 0; % specific values on diagonal
1 1 4 0 0;
1 0 1 5 0;
1 0 1 1 6];
v = diag(H)
% Alternative:
v = H(1:size(H)+1:numel(H))
  4 件のコメント
Jan
Jan 2021 年 2 月 8 日
A "portable" Matlab version is not allowed by the license conditions, as far as I know. Then you are asking for an illegal installation.
acun67 acu
acun67 acu 2021 年 2 月 9 日
thank you for sharing your knowledge.I am not using this installation and will try to solve my problem using Matlab online.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction to Installation and Licensing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by