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

조회 수: 1 (최근 30일)
Syed Mustafa
Syed Mustafa 2016년 2월 14일
댓글: Kayleigh Jayne Moloney 2019년 5월 15일
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by