# How to formulate the following vector?

1 ビュー (過去 30 日間)
M 2022 年 5 月 24 日

I want to folmulate vector V as as the following:
R is attached matrix
The values of the vector should be taken from the R matrix:
V = [ number of the column, the value which exist in the 4th row of the same column, number of the next column, the value which exist in the 4th row of the same column, and so on ......]
The output V should be as the follows ==> V= [1 11 2 1 3 4 ........ ]

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

### 回答 (2 件)

DGM 2022 年 5 月 24 日
Something like this should work:
V = reshape([1:size(R,2); R(4,:)],1,[]);
##### 0 件のコメント表示非表示 -1 件の古いコメント

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

Allen 2022 年 5 月 24 日
r = size(R,2); % Gets the number of rows in the array R
% Creates a row vector 1:r and vertically concatenate with the last row of
% R. Reshapes the 2xr sized array to a 1x2r array with values in the
% correct order.
V = reshape([1:r;R(4,:)],[1,2*r]);

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

### カテゴリ

Find more on Matrix Indexing in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by