Output matrix to x/y/cell value

Hey guys,
I'm looking for a little help with a problem that I can't seem to find anyone else having, probably because it's so simple that it can be solved by someone with decent experience very quickly.
I have a matrix with a bunch of numbers. This is not an image, rather the result of calculations for a value of each cell. In all cases, the cell contains either a zero or some decimal value ie 0.006.
What I need to get is an output of three columns; column number(x)/row number(y)/original value of the cell(ie 0.1).
Any help would be appreciated,
Cheers Marty

 Respuesta aceptada

Titus Edelhofer
Titus Edelhofer el 25 de Nov. de 2014
Hi Martin,
are you looking for something like this:
>> A = rand(2,3)
A =
0.2020 0.3507 0.0538
0.2103 0.1068 0.4271
>> [col,row] = meshgrid(1:size(A,2), 1:size(A,1));
>> [col(:) row(:) A(:)]
ans =
1.0000 1.0000 0.2020
1.0000 2.0000 0.2103
2.0000 1.0000 0.3507
2.0000 2.0000 0.1068
3.0000 1.0000 0.0538
3.0000 2.0000 0.4271
Titus

1 comentario

Martin
Martin el 26 de Nov. de 2014
Yes! thankyou so much, Titus. Works perfectly :) Thanks!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 25 de Nov. de 2014

Comentada:

el 26 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by