MATLAB - The Language of Technical Computing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • foilman8805
    smoke wheat hail satin
    FFR Simfile Author
    • Sep 2006
    • 5704

    #1

    MATLAB - The Language of Technical Computing

    Love it or hate it, it's a high level computing language and an excellent analysis tool. I know we have some aspiring engineers in college who either are, or are soon to be immersed in this program and will be looking for help. The learning curve is extremely high, especially if you have no prior experience with programming. In this thread, you can post your code, ask for help from those of us who are more experienced, show people cool things they never knew about MATLAB, "code golf" or simply just show off.

    If you want to display computer code properly, please use the code tags as shown below. If you are unaware of how to do that, simply quote this post and you will see the necessary BBCode.

    Code:
    Place any code inside the code tags and it will be automatically formatted. This will make it easier for people to help you.
    Last edited by foilman8805; 10-17-2011, 09:03 PM.
  • tangomango
    FFR Player
    • May 2007
    • 1134

    #2
    Re: MATLAB - The Language of Technical Computing

    Wow haven't posted in ages...

    Does anyone know of a good site that gives tutorials on MATLAB? I'm struggling with it in my engineering class.

    Comment

    • woker-X
      .... :.. .:. ::
      FFR Simfile Author
      • Mar 2007
      • 1040

      #3
      Re: MATLAB - The Language of Technical Computing

      what are you doing with it??

      you can search for matlab exchange on google to get some programs similar to what you are doing.

      EDIT: http://www.mathworks.com/matlabcentral/fileexchange/

      Comment

      • foilman8805
        smoke wheat hail satin
        FFR Simfile Author
        • Sep 2006
        • 5704

        #4
        Re: MATLAB - The Language of Technical Computing

        tango, what kind of help are you looking for?

        Comment

        • tangomango
          FFR Player
          • May 2007
          • 1134

          #5
          Re: MATLAB - The Language of Technical Computing

          We learned for-loops, if-or statements, array manipulations and more. I mainly don't understand for-loops. For instance, I was given a 5D array with length of 10 10 20 10 10, and told to use nested for-loops to find the maximum number in the array.

          Do you have any advice on how to learn programming more efficiently? This is my first programming class and I'm having a rough time haha.

          Example of a problem: Write a loop that finds the number under 1000 with the greatest number of
          unique prime factors. (Since many numbers under 1000 have the same `greatest'
          number of unique prime factors, find only the FIRST number that meets this
          criterion.)

          I had
          Code:
          for vector = 1:10
              factors(vector) = length(unique(factor(vector))); %Creates vector of the lengths of unique prime factors
              
          end
          After that I don't know how to find the first largest number from that vector.
          Last edited by tangomango; 02-8-2012, 08:56 PM.

          Comment

          • foilman8805
            smoke wheat hail satin
            FFR Simfile Author
            • Sep 2006
            • 5704

            #6
            Re: MATLAB - The Language of Technical Computing

            The only advice is to program, program and program more. Occasionally seek help from people who know more than you. That's really it. You have to immerse yourself in order to get better. Practice makes perfect, etc.

            And for a beginning programming class, I'm hoping what you really meant was you have a 1D array with 5 elements (length of 5). MATLAB doesn't handle 5D arrays lol.

            Comment

            • tangomango
              FFR Player
              • May 2007
              • 1134

              #7
              Re: MATLAB - The Language of Technical Computing

              To clarify the 5D problem, I was given temperature data from 5 variables (x,y,z,t,s). I'd like to clarify more but it was a quiz problem and I don't really remember the specifics.

              Comment

              • foilman8805
                smoke wheat hail satin
                FFR Simfile Author
                • Sep 2006
                • 5704

                #8
                Re: MATLAB - The Language of Technical Computing

                Originally posted by tangomango
                We learned for-loops, if-or statements, array manipulations and more. I mainly don't understand for-loops. For instance, I was given a 5D array with length of 10 10 20 10 10, and told to use nested for-loops to find the maximum number in the array.

                Do you have any advice on how to learn programming more efficiently? This is my first programming class and I'm having a rough time haha.

                Example of a problem: Write a loop that finds the number under 1000 with the greatest number of
                unique prime factors. (Since many numbers under 1000 have the same `greatest'
                number of unique prime factors, find only the FIRST number that meets this
                criterion.)

                I had
                Code:
                for vector = 1:10
                    factors(vector) = length(unique(factor(vector))); %Creates vector of the lengths of unique prime factors
                    
                end
                After that I don't know how to find the first largest number from that vector.
                Use the "max" function to the find the largest number in an array, i.e.:

                max(factors) will return the maximum number in the array you named factors in your for loop.

                Comment

                • tangomango
                  FFR Player
                  • May 2007
                  • 1134

                  #9
                  Re: MATLAB - The Language of Technical Computing

                  The problem I'm having is that when I try to find the location of the maximum value from 'factors', it does not seem to work. Instead of a displaying '6' as I would like it to, it gives me 1.
                  Code:
                   for vector = 6:10
                      factors(vector) = length(unique(factor(vector))); %Creates vector of the lengths of unique prime factors
                      a = find(max(factors));
                  end
                  disp(a)
                  Thanks for the help by the way.
                  Last edited by tangomango; 02-8-2012, 09:16 PM.

                  Comment

                  • foilman8805
                    smoke wheat hail satin
                    FFR Simfile Author
                    • Sep 2006
                    • 5704

                    #10
                    Re: MATLAB - The Language of Technical Computing

                    If you want to find the location:

                    [a,b] = find(max(factors)); will return the index value of the largest number in the array by row and column, respectively.

                    Then you'd want to do:

                    disp(factors(a,b))

                    Comment

                    • foilman8805
                      smoke wheat hail satin
                      FFR Simfile Author
                      • Sep 2006
                      • 5704

                      #11
                      Re: MATLAB - The Language of Technical Computing

                      Write a loop that finds the number under 1000 with the greatest number of unique prime factors. (Since many numbers under 1000 have the same `greatest' number of unique prime factors, find only the FIRST number that meets this criterion.)

                      Code:
                      for i = 1:999
                         x(i) = length(unique(factor(i)));
                      end
                      
                      y = ind2sub(size(x),find(x==max(x)));
                      answer = min(y);
                      
                      disp('The answer is:')
                      disp(answer)
                      One of many ways to do this. I didn't include everything in the loop though, so maybe I violated the rules. Whatever.
                      Last edited by foilman8805; 02-9-2012, 07:27 PM.

                      Comment

                      • tangomango
                        FFR Player
                        • May 2007
                        • 1134

                        #12
                        Re: MATLAB - The Language of Technical Computing

                        I'm a little confused at this part:

                        Code:
                         y = ind2sub(size(x),find(x==max(x)));
                        answer = min(y);
                        What does ind2sub do? Does it take all of the max values of x into a vector?

                        Comment

                        • foilman8805
                          smoke wheat hail satin
                          FFR Simfile Author
                          • Sep 2006
                          • 5704

                          #13
                          Re: MATLAB - The Language of Technical Computing

                          Dude, when you see something in MATLAB you don't immediately know and you want to know what it does you should consult the help files.

                          Type in the command window "help ind2sub". It'll provide a much better explanation than I can give.

                          Comment

                          Working...