How to convert row*col data into series of column in matlab ?

1 回表示 (過去 30 日間)
Syed Mustafa
Syed Mustafa 2016 年 2 月 14 日
I have data of 100 row*101 col. I want to convert them in series e.g. for first row all column data then in the down for 2nd row all column data and so on. Its means results will be three column only. First column with row no, 2nd column with column no and 3rd column the value for respective row and column. please check the attached file for example
Could you please help me doing this conversion in matlab.
Available data are in ascii format and its possible to open in matlab or excel.

回答 (2 件)

Guillaume
Guillaume 2016 年 2 月 14 日
Your conversion only makes sense if your matrix is sparse (has a lot of zeros), otherwise your converted matrix is going to use a lot more memory and is probably going to be harder to use.
Anyway.
  • If you want all the rows and columns including the ones with zero:
%m: input matrix, in your case 100x101
[rows, cols] = ndgrid(1:size(m,1 ), 1:size(m, 2));
out = [rows(:), cols(:), m(:)]
  • If you just want the location of the non-zeros elements:
%m: input matrix, in your case 100x101
[rows, cols, values] = find(m);
out = [rows, cols, values];

Syed Mustafa
Syed Mustafa 2016 年 2 月 15 日
Thank you all : its already solved

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by