Can I store row numbers of a matrix in a column without using any loop?

12 ビュー (過去 30 日間)
Nagesh A P
Nagesh A P 2018 年 6 月 29 日
コメント済み: Nagesh A P 2018 年 6 月 29 日
How will I store the first column of a matrix as its corresponding row number without using a loop. That is, the first column for a 3x3 matrix as [1 . .;2 . .;3 . .].
  2 件のコメント
Aquatris
Aquatris 2018 年 6 月 29 日
You mean something like this;
A=[1 5 6; 2 7 8;3 9 0];
B = A(:,1); % this will make B = [1;2;3]
Nagesh A P
Nagesh A P 2018 年 6 月 29 日
編集済み: Nagesh A P 2018 年 6 月 29 日
Ok. This is the case. I have a very large data, something like 100,000 data points, so 100,000 rows. I want to store the first column of a matrix newly created (with as many rows as number of data points mentioned) as its corresponding row number. I can do what you've mentioned. But it'll take me a new matrix and another loop to create that matrix. Could you suggest something which takes less time.

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

採用された回答

Nithin Banka
Nithin Banka 2018 年 6 月 29 日
a = magic(3);
a(:, 1) = [1:3]; % This will store the row index in the first column of 'a'
  3 件のコメント
Nagesh A P
Nagesh A P 2018 年 6 月 29 日
Thad did save my time bro. thanks
Nagesh A P
Nagesh A P 2018 年 6 月 29 日
Thanks @nithin and @Guillaume

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by