Results 1 to 2 of 2
  1. #1
    nvwin is offline Member
    Join Date
    May 2016
    Posts
    6
    Rep Power
    0

    Default Produce repmat() method using java

    arr = [6,3,9,0];

    repmat(arr,2,1,2) method in matlab produce a format which is :

    L(:,:,1) =

    6 3 9 0
    6 3 9 0


    L(:,:,2) =

    6 3 9 0
    6 3 9 0

    ************************************************** **************************

    the java code is :

    Java Code:
      import java.util.*;
       class test23{
       public static void main ( String [] args ) {
        int[] arr = {6,3,9,0};
        test23 test = new test23();
       System.out.println(Arrays.deepToString(test.repmat(arr,3,1)));
    	}
    
     public static int[][] repmat (int[] array, int rows, int columns)
      {
        int arrayLength = array.length;
        int resultColumns = arrayLength * columns;
    
        int[][] result = new int[rows][resultColumns];
    
        int z = 0;
    
        for (int r = 0; r < rows; r++)
        {
          for (int c = 0; c < resultColumns; c++)
    
          {
            result[r][c] = array[z++];
            if (z >= arrayLength)
             {
              z = 0;
    	     }
           }
          }
    
        return result;
      }
    }
    the java out put is : [[6,6],[3,3],[9,9],[0,0]],[[[6,6],[3,3],[9,9],[0,0]]
    ************************************************** ******************************

    it does not produce a copy array format as repmat() in matlab.


    please any suggestion.
    Last edited by nvwin; 05-15-2016 at 09:34 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: Produce repmat() method using java

    it does not produce same out put .
    Please explain what you are comparing and why the outputs should be the same.
    Please post both outputs and say if any are correct.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Program to produce a random landscape in Java
    By no s e e d s in forum Java Applets
    Replies: 1
    Last Post: 12-16-2009, 12:56 AM
  2. help with a program to produce a landscape picture
    By no s e e d s in forum New To Java
    Replies: 1
    Last Post: 12-16-2009, 12:55 AM
  3. Use unicode in iReport to produce reports
    By nasir_7b in forum Advanced Java
    Replies: 0
    Last Post: 03-17-2008, 12:53 PM
  4. text Strings to produce letters
    By dc2acgsr99 in forum New To Java
    Replies: 7
    Last Post: 01-29-2008, 09:08 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •