根据另一个矩阵删除矩阵行?

时间:2016-02-15 23:45:44

标签: matlab matrix

我要删除矩阵的行数,使其行数与另一个矩阵相同

例如:

import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import static org.junit.Assert.assertNotNull;
import static org.powermock.api.mockito.PowerMockito.mock;
import static org.powermock.api.mockito.PowerMockito.whenNew;

@RunWith(PowerMockRunner.class) // delegate test running to PowerMock
@PrepareForTest(OuterClass.class) // mark classes for instrumentation so magic can happen
public class InnerClassTest {

    @Test
    public void shouldNotThrowException() throws Exception { // oh, the puns!
        // make a mockery of our inner class
        OuterClass.InnerClass innerClassMock = mock(OuterClass.InnerClass.class);

       // magically return the mock when a new instance is required
       whenNew(OuterClass.InnerClass.class).withAnyArguments().thenReturn(innerClassMock);

        // yey, no UnsupportedOperationException here!
        OuterClass outerClass = new OuterClass();
        assertNotNull(outerClass);
    }
}

我该怎么做才能变成

a = [ 1 2
      3 4
      5 6 ]

b = [7 8]

1 个答案:

答案 0 :(得分:4)

使用size

a = a(1:size(b,1), 1:size(b,2));

size(...,1)是行数,size(...,2)是列数。因此,这会从a中选择正确的行数和列数。