How to convert row*col data into series of column in matlab ?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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.
Risposte (2)
Guillaume
il 14 Feb 2016
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 Commenti
Vedere anche
Categorie
Scopri di più su Logical in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!