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!