Go Back   Flash Flash Revolution > General Discussion > Technology

Reply
 
Thread Tools Display Modes
Old 10-17-2011, 09:59 PM   #1
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default 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 at 10:03 PM..
foilman8805 is offline   Reply With Quote
Old 02-8-2012, 09:31 PM   #2
tangomango
FFR Player
FFR Veteran
 
tangomango's Avatar
 
Join Date: May 2007
Posts: 1,134
Default 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.
tangomango is offline   Reply With Quote
Old 02-8-2012, 09:34 PM   #3
woker-X
.... :.. .:. ::
Retired StaffFFR Simfile AuthorFFR Veteran
 
woker-X's Avatar
 
Join Date: Mar 2007
Posts: 1,031
Default 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/
woker-X is offline   Reply With Quote
Old 02-8-2012, 09:50 PM   #4
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default Re: MATLAB - The Language of Technical Computing

tango, what kind of help are you looking for?
foilman8805 is offline   Reply With Quote
Old 02-8-2012, 09:50 PM   #5
tangomango
FFR Player
FFR Veteran
 
tangomango's Avatar
 
Join Date: May 2007
Posts: 1,134
Default 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 at 09:56 PM..
tangomango is offline   Reply With Quote
Old 02-8-2012, 09:55 PM   #6
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default 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.
foilman8805 is offline   Reply With Quote
Old 02-8-2012, 10:02 PM   #7
tangomango
FFR Player
FFR Veteran
 
tangomango's Avatar
 
Join Date: May 2007
Posts: 1,134
Default 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.
tangomango is offline   Reply With Quote
Old 02-8-2012, 10:05 PM   #8
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default Re: MATLAB - The Language of Technical Computing

Quote:
Originally Posted by tangomango View Post
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.
foilman8805 is offline   Reply With Quote
Old 02-8-2012, 10:14 PM   #9
tangomango
FFR Player
FFR Veteran
 
tangomango's Avatar
 
Join Date: May 2007
Posts: 1,134
Default 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 at 10:16 PM..
tangomango is offline   Reply With Quote
Old 02-8-2012, 10:16 PM   #10
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default 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))
foilman8805 is offline   Reply With Quote
Old 02-8-2012, 10:48 PM   #11
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default 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 at 08:27 PM..
foilman8805 is offline   Reply With Quote
Old 02-12-2012, 10:45 PM   #12
tangomango
FFR Player
FFR Veteran
 
tangomango's Avatar
 
Join Date: May 2007
Posts: 1,134
Default 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?
tangomango is offline   Reply With Quote
Old 02-12-2012, 10:52 PM   #13
foilman8805
smoke wheat hail satin
FFR Simfile AuthorFFR Veteran
 
foilman8805's Avatar
 
Join Date: Sep 2006
Location: LA baby
Age: 35
Posts: 5,704
Default 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.
foilman8805 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 04:58 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution