How can I insert the row of matrix A into matrix M if the whole row of matrix A and matrix B are the same?
There is the example
>> A = [1 2; 3 4]
A =
1 2
3 4
>> B = [1 2; 3 6]
B =
1 2
3 6
M =
1 2

 Respuesta aceptada

JESUS DAVID ARIZA ROYETH
JESUS DAVID ARIZA ROYETH el 15 de Feb. de 2020

0 votos

M=A(ismember(A,B,"rows"),:)

7 comentarios

Walter Roberson
Walter Roberson el 15 de Feb. de 2020
Is use of double quotes defined in octave?? I do not know.
The octave experts are elsewhere, at a different resource. Octave is a different programming language and not a suitable question for MATLAB Answers.
Les Beckham
Les Beckham el 15 de Feb. de 2020
Having been forced to use Octave lately due to not having Matlab available currently, I can answer Walter's question.
Double quoted strings are supported in Octave (and seem to be actually preferred as they are used almost exclusively in the documentation for things like fprintf). I still use single quotes for the most part, as that is what I got used to over the years in Matlab. Strings were just introduced when I lost access to Matlab and I never got into the habit of using them.
Walter is right, of course, that asking Octave questions in Matlab Answers isn't really appropriate.
I really do miss Matlab. :(
Walter Roberson
Walter Roberson el 15 de Feb. de 2020
Thanks, Les.
Perhaps you could get a Home license?
Michelle Leung
Michelle Leung el 16 de Feb. de 2020
M=A(ismember(A,B,"rows"),:) works in octave. However, if I also want to compare the column what should I do? I have check M=A(ismember(A,B," column"),:) doesn't work. I am new in using octave and I only have some knowledge on the primary function of creating a matrix and some simple calculations.
Walter Roberson
Walter Roberson el 16 de Feb. de 2020
Transpose the data you send into ismember so that the column you want to compare becomes a row for the purpose of comparing.
Michelle Leung
Michelle Leung el 16 de Feb. de 2020
Yeah, I got it!! Thanks, Roberson
Rik
Rik el 16 de Feb. de 2020
Note that Matlab and Octave are sufficiently similar that basic tutorials will work for both. There are several places you can find the most important syntax differences. One of them you encountered here: single and double quotes are interchangeable in Octave, in Matlab they are not.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Preguntada:

el 15 de Feb. de 2020

Comentada:

Rik
el 16 de Feb. de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by