Тёмный

MATLAB Function Tutorial 

Ilya Mikhelson
Подписаться 8 тыс.
Просмотров 214 тыс.
50% 1

Опубликовано:

 

27 окт 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 53   
@kilianjames1116
@kilianjames1116 3 года назад
incredibly helpful and simply explained, thanks so much!
@IlyaMikhelson
@IlyaMikhelson 3 года назад
My pleasure!
@andywestwood2972
@andywestwood2972 8 лет назад
An outstanding tutorial, clear and with valuable common/standard practice issues. Same for the other tutorials on your channel. A very good balance between capability and options. Thanks so much ....
@IlyaMikhelson
@IlyaMikhelson 8 лет назад
+Andy Westwood Thank you for your kind words!
@rabiabatool9598
@rabiabatool9598 4 года назад
Thanks a lot....it was very useful.....I did my Matlab task just because of your video.....
@IlyaMikhelson
@IlyaMikhelson 4 года назад
I'm very glad I could help!
@Joseangel9archi1
@Joseangel9archi1 8 лет назад
Thanks a lot, it was really useful. Greetings from Spain!
@ub437
@ub437 5 лет назад
thank you man,i've lost 3 hours and then i see this video
@mosesmccabe8983
@mosesmccabe8983 10 лет назад
wow just awesome. thanks for this very detail and well explain video
@MyThoughtsAreBelow
@MyThoughtsAreBelow 8 лет назад
Excellent tutorial sir
@nevpires84
@nevpires84 9 лет назад
Great Video!
@anzarzahid7266
@anzarzahid7266 7 лет назад
Thanks a lot, it was really useful.
@nacht98
@nacht98 9 лет назад
very very good!
@ahmadfakih3451
@ahmadfakih3451 6 лет назад
Thank you so much!
@djokatore45
@djokatore45 9 лет назад
thank you for this example, very helpful :)
@wgeorge1602
@wgeorge1602 9 лет назад
very good!!!
@ericarnaud5062
@ericarnaud5062 9 лет назад
Thank you so much, that was awesome explained
@9circlesofMATH
@9circlesofMATH 4 года назад
hello there, i have problem it says this 'Undefined function or variable 'my_max'. when i run it
@IlyaMikhelson
@IlyaMikhelson 4 года назад
You have to be the same directory as where you saved your function. Otherwise, MATLAB doesn't know where to look for your code.
@MrShortReels
@MrShortReels 4 года назад
Sir I write like u wrote, I had mentioned in command window that say FUNCTION definition are not permitted in this context.. Why
@grishp8203
@grishp8203 6 лет назад
Hey guys, Why is a function declared at the beginning of the program? Can I declare it in between anywhere in my code? Thanks
@IlyaMikhelson
@IlyaMikhelson 6 лет назад
You can, but it can only be accessed from outside of that file if it is the first function (and the file has the same name).
@mohamedabdelfattah8627
@mohamedabdelfattah8627 7 лет назад
Thanks a lot.
@IlyaMikhelson
@IlyaMikhelson 7 лет назад
My pleasure!
@michaelellison9757
@michaelellison9757 10 лет назад
well said!
@eliefant6353
@eliefant6353 6 лет назад
how would i write a function rect = rect_aperture(r1, c1, r2, c2) that constructs a rectangular aperture on a 512 by 1024 grid? so the top left (r1,c1) and bottom right (r2,c2)?
@IlyaMikhelson
@IlyaMikhelson 6 лет назад
You would start with (as you said): function rect = rect_aperture(r1,c1,r2,c2) I would also recommend making the dimensions (512 and 1024) as additional arguments, in order to make it more robust. If you want, you could make those variables have default values of 512 and 1024, if that's what makes sense in the context of your problem. Then, you would use the physics of your particular problem (which I don't know) in order to create the grid. I hope that helps!
@Techformative557
@Techformative557 6 лет назад
Hey! at 5:45 could a while loop be used instead of if v(ii) ?
@IlyaMikhelson
@IlyaMikhelson 6 лет назад
You could potentially replace the for loop with a while loop (with careful variable management), but I don't think I see how to replace a conditional statement with a loop. Can you please elaborate on your idea?
@gfdhgfth
@gfdhgfth 8 лет назад
Hi I was wondering if you have any expertise with the "comet" function and would be able to help me sort out some code? I have this code here: a=(1:0.5:1000); angle=a.*75; x=cos(angle); y=sin(angle); t=0.5; Ex=x.*Er; Ey=y.*Er; DELAY = 1; %edit comet %axis=5*10^12; comet(Ex,Ey,0) %axis([-axis axis -axis axis]); And it works except for the fact that it's too fast! I can't get it to slow down with any pause or delay functions, any ideas?
@IlyaMikhelson
@IlyaMikhelson 8 лет назад
+Diamond Blooded I have actually never used the "comet" function, but after some exploration, I think I have a solution for you. My solution is to plot the figure over and over, but to emphasize the location of the current plotted point, as well as a trailing tail. (By the way, you didn't define "Er" in the code you posted, so I could not run it as is. I just made Er=1 to try it out.) You can control the length of the tail, as well as the delay between subsequent plots. Note, the code below will run for a long time, because I made the delay long to emphasize the operation. Here is my code, and please feel free to ask questions. a=(1:.5:1000); angle=a.*75; x=cos(angle); y=sin(angle); Er = 1; Ex=x.*Er; Ey=y.*Er; tail_len = 5; % tail length in number of points delay_time = 0.5; % delay time in seconds figure(1); hold on; plot(Ex(1:tail_len),Ey(1:tail_len),'r','LineWidth',4); plot(Ex(tail_len),Ey(tail_len),'ro','MarkerSize',12); pause(delay_time); hold off; for ii = tail_len:tail_len:length(Ex)-tail_len figure(1);plot(Ex(1:ii),Ey(1:ii),'b'); hold on; plot(Ex(ii:ii+tail_len),Ey(ii:ii+tail_len),'r','LineWidth',4); plot(Ex(ii+tail_len),Ey(ii+tail_len),'ro','MarkerSize',12); pause(delay_time); hold off; end figure(1);plot(Ex(1:ii),Ey(1:ii),'b'); hold on; plot(Ex(ii:end),Ey(ii:end),'r','LineWidth',4); plot(Ex(end),Ey(end),'ro','MarkerSize',12); hold off;
@gfdhgfth
@gfdhgfth 8 лет назад
+Ilya Mikhelson Thankyou this gives a perfect representation of what i was looking for (Er was meant to be a few million but scaling doesn't matter). Although this would be perfect for what I have asked i need to be able to copy this multiple times and plot 9 plots on 1 graph, but thankyou so much for your help! Thankyou
@IlyaMikhelson
@IlyaMikhelson 8 лет назад
+Diamond Blooded You can definitely make this a modular function. Then, you can use it over and over compactly. For example: function my_comet(x, y, tail_len, delay_time) % Insert my code with proper modifications to use the user input instead of hard-coding within the function.
@RishabhR8
@RishabhR8 9 лет назад
Hey, if I have to create a function with 2 input arguments (vectors) and the output should be the value of the derivative, how is it written?
@IlyaMikhelson
@IlyaMikhelson 9 лет назад
+Rishabh Vyas The function would look something like this: function derivative = my_derivative(vector_1, vector_2) % Code The comment will be replaced with whatever you are doing with the input vectors. I hope this helps!
@MegaAnonynous
@MegaAnonynous 3 года назад
what is -inf ?
@IlyaMikhelson
@IlyaMikhelson 3 года назад
That is negative infinity, basically a number that is smaller than any other number.
@vALIentsInfoTech
@vALIentsInfoTech 7 лет назад
For more understanding watch this video: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-t6062Nwt0JE.html
@yamenhazimi2947
@yamenhazimi2947 7 лет назад
how can i input any function i want in matlab. i mean something like (input('enter yout function')) ty
@IlyaMikhelson
@IlyaMikhelson 7 лет назад
Would you want them to input the entire function in one line, with all of the proper syntax?
@yamenhazimi2947
@yamenhazimi2947 7 лет назад
yes
@IlyaMikhelson
@IlyaMikhelson 7 лет назад
The problem with this is that a function needs to be called by its name, with potential input arguments. Therefore, it must be properly saved in the file path. If the thing you want is to have the user input various commands to execute, though, you can use something like this: eval(input('Enter a command: ','s')); This will prompt the user to input commands, save them as a string, and then evaluate the string.
@shraddhatripathi4862
@shraddhatripathi4862 6 лет назад
thanks a lot sir
@IlyaMikhelson
@IlyaMikhelson 6 лет назад
My pleasure!
@mustafabasediq9818
@mustafabasediq9818 7 лет назад
than u very much
@mariorodriguez219
@mariorodriguez219 2 года назад
so confusing
@IlyaMikhelson
@IlyaMikhelson 2 года назад
Thank you for watching and commenting. I would love to hear any elaboration so as to improve for the future!
@MrMadrid1984
@MrMadrid1984 8 лет назад
Hey, How to write a function that its number of outputs depends on the value of its input...for example: [n1,n2,.........nr]=myfunction(r) is this possible in Matlab?
@IlyaMikhelson
@IlyaMikhelson 8 лет назад
You can use the "varargout" output variable, which is a cell array you fill in inside the function. For example, "function [varargout] = myfunction(r)". In the function, you can use the value of "r" to determine how long to make the cell array "varargout". I hope this helps!
@MrMadrid1984
@MrMadrid1984 8 лет назад
Thank you for your prompt reply. I read about "varargout" but still confused how to use it!
@IlyaMikhelson
@IlyaMikhelson 8 лет назад
Here is an example: function [varargout] = myfunction(r) varargout = cell(1,r); for ii = 1:r varargout{ii} = ii*2; end You can now call it with up to "r" output variables, for example "[w,x,y,z] = myfunction(4)", in which case you will get w=2, x=4, y=6, z=8. You do have to be careful with error checking inside the function, though, since the user can accidentally request more outputs than you assign. You can do this with "nargout", which will tell you the number of requested output arguments. However, depending on your usage, it may be easier to simply have an output matrix or cell array, and to fill it in inside the function. Then, you will always call the function with one output argument (i.e. the matrix or cell array), instead of several (e.g. [w,x,y,z] = ...). I hope this makes more sense now. If not, please ask followup questions!
Далее
Brawl Stars expliquez ça
00:11
Просмотров 6 млн
Исповедь / Мася
2:47:10
Просмотров 183 тыс.
ДУБАЙСКАЯ ШОКОЛАДКА 🍫
00:55
Просмотров 2,1 млн
MATLAB For Loop Tutorial
13:37
Просмотров 662 тыс.
MATLAB Output Tutorial
9:07
Просмотров 54 тыс.
MATLAB Debugging Tutorial
10:40
Просмотров 54 тыс.
Function M-Files in MATLAB
9:11
Просмотров 248 тыс.
Write a function in MATLAB
4:29
Просмотров 365 тыс.
Textscan and Fscanf in Matlab
9:39
Просмотров 42 тыс.
How to Call a Function in MATLAB
2:03
Просмотров 7 тыс.