时间:2016-05-26 13:34:55

标签: matlab

我有一个35 x 24数字矩阵。 35行中的每一行显然都具有最大值。我试着编写一小段代码来确定24列中哪一列包含这些最大值中的大部分。问题是不允许循环。

例如,如果30个不同行的最大值都发生在第7列,那么我希望MATLAB返回答案7,因为这是具有最大行值的列。

2 个答案:

答案 0 :(得分:2)

如果每行中的值都是唯一的,我们只需使用max的第二个输出结合mode来确定哪个列最常包含每行的最大值。

% Find the column which contains the maximum value
[~, column] = max(data, [], 2);
result = mod(column);   

但是,下面是一个更通用的解决方案,允许每行多次出现给定的最大值。

maximaPerColumn = sum(bsxfun(@eq, data, max(data, [], 2)), 1);
result = find(maximaPerColumn == max(maximaPerColumn));

<强>解释

首先,我们要计算每行的最大值(跨列的最大值,维度2)。

rowMaxima = max(data, [], 2);

如果值等于该行的最大值,则我们希望用1替换每一行,否则为0。我们可以使用bsxfun轻松完成此操作。

isMaxOfRow = bsxfun(@eq, data, rowMaxima);

然后我们想弄清楚给定列包含最多行的次数。我们只需sum向下列即可获得此内容。

maximaPerColumn = sum(isMaxOfRow, 1);

现在我们要查找包含最大最大数量的列。我们使用find,因为多个列可能包含相同数量的最大值。

result = find(maximaPerColumn == max(maximaPerColumn));

答案 1 :(得分:0)

我认为你正在寻找这个:

java.rmi.RemoteException: SOAP Fault:javax.xml.rpc.soap.SOAPFaultException: Failed to send request
Detail:
<detail><bea_fault:stacktrace xmlns:bea_fault="http://www.bea.com/servers/wls70/webservice/fault/1.0.0">java.net.ConnectException: Connection timed out
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
        at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
        at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
        at java.net.Socket.connect(Socket.java:529)
        at com.sun.net.ssl.internal.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:559)
        at com.sun.net.ssl.internal.ssl.BaseSSLSocketImpl.connect(BaseSSLSocketImpl.java:141)
        at sun.net.NetworkClient.doConnect(NetworkClient.java:163)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:394)
        at sun.net.www.http.HttpClient.openServer(HttpClient.java:529)
        at sun.net.www.protocol.https.HttpsClient.&lt;init&gt;(HttpsClient.java:272)
        at sun.net.www.protocol.https.HttpsClient.New(HttpsClient.java:329)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(AbstractDelegateHttpsURLConnection.java:172)
        at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:911)
        at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:158)
        at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:1014)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:230)
        at weblogic.webservice.binding.http11.Http11ClientBinding.send(Http11ClientBinding.java:438)
        at weblogic.webservice.core.handler.ClientHandler.handleRequest(ClientHandler.java:38)
        at weblogic.webservice.core.HandlerChainImpl.handleRequest(HandlerChainImpl.java:144)
        at weblogic.webservice.core.ClientDispatcher.send(ClientDispatcher.java:235)
        at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDispatcher.java:146)
        at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:449)
        at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:435)
        at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:306)
        at com.cengage.ips.IPSInquiryWebServiceSoap_Stub.itemInquiry(IPSInquiryWebServiceSoap_Stub.java:64)
        at main.java.com.cengage.ips.ServiceManager.getItemResponse(ServiceManager.java:57)
        at main.java.com.cengage.ips.process.ResponseHandler.itemResponseHandler(ResponseHandler.java:49)
        at main.java.com.cengage.ips.IPSIntegration.process(IPSIntegration.java:63)
        at main.java.com.cengage.ips.IPSIntegration.run(IPSIntegration.java:37)
        at main.java.com.cengage.ips.IPSIntegration.main(IPSIntegration.java:28)
</bea_fault:stacktrace></detail>; nested exception is:
        javax.xml.rpc.soap.SOAPFaultException: Failed to send request
        at com.cengage.ips.IPSInquiryWebServiceSoap_Stub.itemInquiry(IPSInquiryWebServiceSoap_Stub.java:69)
        at main.java.com.cengage.ips.ServiceManager.getItemResponse(ServiceManager.java:57)
        at main.java.com.cengage.ips.process.ResponseHandler.itemResponseHandler(ResponseHandler.java:49)
        at main.java.com.cengage.ips.IPSIntegration.process(IPSIntegration.java:63)
        at main.java.com.cengage.ips.IPSIntegration.run(IPSIntegration.java:37)
        at main.java.com.cengage.ips.IPSIntegration.main(IPSIntegration.java:28)
Caused by: javax.xml.rpc.soap.SOAPFaultException: Failed to send request
        at weblogic.webservice.core.ClientDispatcher.receive(ClientDispatcher.java:317)
        at weblogic.webservice.core.ClientDispatcher.dispatch(ClientDispatcher.java:147)
        at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:449)
        at weblogic.webservice.core.DefaultOperation.invoke(DefaultOperation.java:435)
        at weblogic.webservice.core.rpc.StubImpl._invoke(StubImpl.java:306)
        at com.cengage.ips.IPSInquiryWebServiceSoap_Stub.itemInquiry(IPSInquiryWebServiceSoap_Stub.java:64)
        ... 5 more

示例:

sum(A==max(A,[],2))

返回:

A = [1 1 1; 
2 2 2; 
3 2 1]

M = sum(A==max(A,[],2))

第一列的行最大值最大。您可以使用[3 2 2] 来标识此列。

find