Combine different Matrix together

1 visualización (últimos 30 días)
Ali
Ali el 30 de Mayo de 2016
Comentada: Ali el 31 de Mayo de 2016
I am trying to write a convertor, for converting a text file to another text file. I read three different matrix, and I want to combine them.
In the following, I put a small set of data.
The first matrix is this:
0 1
3 0
1 4
This is the second matrix:
-0
-1
-0
As you see, matrix one and two have the same number of rows. This is the third matrix:
0 1
0 2
2 1
3 0
3 2
2 0
1 4
1 6
I want to produce the following:
-0: 0 1
1: 0 2
2: 2 1
-1: 3 0
4: 3 2
5: 2 0
-0: 1 4
7: 1 6
I was wondering if you kindly help me.
Thanks
  3 comentarios
Azzi Abdelmalek
Azzi Abdelmalek el 30 de Mayo de 2016
what is this?
-0: 0 1
Ali
Ali el 31 de Mayo de 2016
Many thanks. I want to print data in this way.

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 31 de Mayo de 2016
firstcol = cellstr( num2str( (0:size(Third,1)-1).', '%d:') );
[tf, idx] = ismember(Third, First, 'rows');
firstcol(tf) = Second(idx(tf));
Output = [firstcol, num2cell(Third)];
  5 comentarios
Walter Roberson
Walter Roberson el 31 de Mayo de 2016
firstcol = (0:size(Third,1)-1).';
[tf, idx] = ismember(Third, First, 'rows');
firstcol(tf) = Second(idx(tf));
fprintf( '%3d: %3d %3d\n', [firstcol, Third].');
Ali
Ali el 31 de Mayo de 2016
Thank you very much Walter Roberson . You really helped me here.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by