How to convert row*col data into series of column in matlab ?
1 回表示 (過去 30 日間)
古いコメントを表示
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
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];
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!