how use reshape ?

14 visualizaciones (últimos 30 días)
pruth
pruth el 23 de Nov. de 2017
Comentada: pruth el 23 de Nov. de 2017
i have mat file contains data. as follow
2 5 4 7 8
2 5 8 4 6
1 5 2 5 8
3 6 4 8 4
I wants it's output as a
1 1 2
2 1 2
3 1 1
4 1 3
1 2 5
2 2 5
3 2 5
4 2 6
1 3 4
2 3 8
3 3 2
4 3 4
1 4 7
2 4 4
3 4 5
4 4 8
1 5 8
2 5 6
3 5 8
4 5 4
where first vector is row number second vector is column number and third vector is data value according to row and column number. This is just an example. in reality I have a matrix of 120*288. hope you understand.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 23 de Nov. de 2017
Editada: Andrei Bobrov el 23 de Nov. de 2017
data = [2 5 4 7 8
2 5 8 4 6
1 5 2 5 8
3 6 4 8 4];
[x,y] = ndgrid(1:size(data,1),1:size(data,2));
out = [x(:),y(:),data(:)];
or
d = data;
d(d == 0) = nan;
[x,y,v] = find(d);
out = [x,y,v];
out(isnan(out)) = 0;
or
out = [fullfact(size(data)),data(:)];
  1 comentario
pruth
pruth el 23 de Nov. de 2017
thank you sir.

Iniciar sesión para comentar.

Más respuestas (1)

KSSV
KSSV el 23 de Nov. de 2017
A = [2 5 4 7 8
2 5 8 4 6
1 5 2 5 8
3 6 4 8 4];
C1 = repmat(1:4,1,5)' ;
C2 = repelem(1:4,5)' ;
C3 = A(:) ;
C = [C1 C2 C3]

Categorías

Más información sobre Modeling en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by