Matlab矩阵重复值

时间:2016-09-29 01:41:43

标签: matlab matrix

我的矩阵: e =

 1     2
 2     3
 3     3
 4     3
 5     2

我想从第一个coloumn重复值,与同一行中第二个coloumn的数字重复。我想让我的矩阵像: e =

 1     2
 1     2
 2     3
 2     3
 2     3
 3     3
 3     3
 3     3
 4     3
 4     3
 4     3
 5     2
 5     2
 thank you for your help...

1 个答案:

答案 0 :(得分:1)

您可以使用repelem重复行索引,然后从import java.io.*; import java.net.*; class ft_client { public static void main(String args[]) throws Exception { int byteSize = 2022386; int bytesRead; /* * Asks user for IP and port: */ BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter an IP address: "); String ipAddress = inFromUser.readLine(); System.out.println("Enter a port: "); String port = inFromUser.readLine(); Socket clientSocket; try { // Makes socket, port, and calls connect. Assumes it's TCP: clientSocket = new Socket(ipAddress, Integer.valueOf(port)); } catch (Exception e) { System.out.println(e.getMessage()); return; } // Creates InputStream from server to get file size and other messages: BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream())); // Anything written to this will be sent to the server: DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream()); // Asks for a file name to download from the server: System.out.println("What file do you want?: "); String message = inFromUser.readLine(); outToServer.writeBytes(message + "\n"); inFromUser.close(); // Listens for confirmation from server. // If the file exists, the file size is delivered here: String response = inFromServer.readLine(); System.out.println("File size: " + response); if (response.equals("File does not exist!")) { return; } // Receives file from server: byteSize = (int) Integer.valueOf(response); byte[] byteArray = new byte[byteSize]; InputStream is = clientSocket.getInputStream(); // calling clientSocket.getInputStream() twice??? FileOutputStream fos = new FileOutputStream(message); BufferedOutputStream bos = new BufferedOutputStream(fos); // Continuously writes the file to the disk until complete: int total = 0; while ((bytesRead = is.read(byteArray)) != -1) { bos.write(byteArray, 0, bytesRead); total += bytesRead; } bos.close(); System.out.println("File downloaded (" + total + " bytes read)"); clientSocket.close(); } } 抓取这些行:

e

如果你使用的是2015a之前没有new_e = e(repelem(1:size(e,1), e(:,2)), :); 的MATLAB版本,这是另一种方法:

repelem