Octave--compare two matrix

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

 采纳的回答

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

7 个评论

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.
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. :(
Thanks, Les.
Perhaps you could get a Home license?
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.
Transpose the data you send into ismember so that the column you want to compare becomes a row for the purpose of comparing.
Yeah, I got it!! Thanks, Roberson
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.

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Octave 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by