3/2/2023 0 Comments Matlab vectorize a matrix![]() ![]() Vec(2) % This gives us the second element of the vector % Access elements in a vector using parentheses For now, we'll call our variable "vec" so we remember that it's a vector. Using descriptive names will help you later. A note on names: we don't have to call our variables only "a" all the time. ![]() Can you create a row vector? A column vector? The row 1 2 3 above the row 4 5 6? The column 1 3 5 beside the column 2 4 6? Vector access Try creating different arrangements of the numbers 1 through 6. How to enter the matrix a = % This is a rowĪ = % This is also a row, the commas are optionalĪ = % This is a column: the semicolons make a new rowĪ = % This is two columns, three rows % How do I enter a whole range of numbers?Ī = % 1 through 10, counting by 1, as a rowĪ = % Start at 1, count up by twos, don't go past 10Ī = % Start at 10, go down by 1, don't go past 4Ī = % Make three rows of three each % Transpose operator flips rows and columns % You can also cause output to be shown with the "display" command: % The command you run still causes changes in the workspace, % so your variable is different next time you look at it % You can use a semicolon to suppress output. You can view the contents with "who" ("whos" is similar and gives you more information) who This is useful to you for keeping track of the variables you've assigned. You can view this table in the "workspace" in your matlab editor. MATLAB uses a table to look up the variables. Try typing "darth" and % then hitting tab. % Also, we can't use a hyphen, because "han-solo" would be read as "han" minus % "solo"! % Another neat feature of the prompt: If you type part of a variable name and % then hit "tab", you can see possible completions. ![]() % Note that we use underscores instead of spaces in variable names. In % general, it's a VERY good idea to use descriptive names for your % variables. % We don't have to be boring and use single letters as variable names. When you type "a = 1", it puts "1" in the lookup table as the % value for "a". When you type % something, like "a", it looks in the lookup table for the associated % value. % The way this works is that MATLAB has a lookup table. % If b = a, then what happens when we change a? % Can we assign a variable to another variable? What happens? % Now, the value of our variable "a" won't change. We can assign values to variables with = a = 7 % % If you start typing and then use the up arrow before you're done, it will % find you all past commands that start with the letters you just typed. % You can use the "up" arrow at the prompt (">") to go back to previous % commands you typed. MATLAB as Calculator % Copy these lines to the prompt (">" in the other window) and run them % one at a time: Type your commands after ">" and hit enter. Work by typing these commands into the interpreter: the window with the line starting with ">". Let's familiarize ourselves with the MATLAB interface. Why MATLAB, not a different language? * Common in the field * Interpreted - see results immediately * Data visualization Introduction to Matlab - Interface Why use code in this course? So you can try out the math. ![]() Why code in general? You can write your own analyses. MATLAB is a programming language and an environment.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |