1 / 33

آموزش نرم افزار MATLAB

بسم الله الرّحمن الرّحيم. آموزش نرم افزار MATLAB. علی دانش گروه رباتیک دانشگاه پیام نور. چند نکته. امکان کامنت چندخطی (بلوکی) در نسخه 7 %{ %} امکانات دیباگ کردن امکان Cell Mode در Script نویسی (نسخه 7) دموهای جالب و مفید demo. توابع تو در تو ( nested function ).

thetis
Télécharger la présentation

آموزش نرم افزار MATLAB

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. بسم الله الرّحمن الرّحيم آموزش نرم افزارMATLAB علی دانش گروه رباتیک دانشگاه پیام نور

  2. چند نکته • امکان کامنت چندخطی (بلوکی) در نسخه 7 %{ %} • امکانات دیباگ کردن • امکان Cell Mode در Script نویسی (نسخه 7) • دموهای جالب و مفید demo

  3. توابع تو در تو (nested function) • اشتراک گذاری داده ها • ساختن توابع سفارشی • ساختن توابع سفارشی با داشتن حالت داخلی

  4. به اشتراک گذاشتن داده ها >> type taxDemo.m function y = taxDemo(income) % Calculate the tax on income: AdjustedIncome = income - 6000; y = computeTax; function y = computeTax % Can see the variable 'AdjustedIncome' y = 0.28 * AdjustedIncome; end end

  5. ساختن توابع سفارشی >> type makefcn.m function fcn = makefcn(a, b, c) % Return handle to nested function: fcn = @parabola; function y = parabola(x) % Can see the variables 'a','b', and 'c' y = a * x .^ 2 + b .* x + c; end end

  6. [ادامه] توابع سفارشی • f = makefcn(3, 2, 10); • g = makefcn(0, 5, 25); • این دو handle به دو تابع متفاوت (ضرایب متفاوت) اشاره می کنند که می توان مقدار هر کدام را محاسبه کرد و یا به عنوان پارامتر به توابع دیگر منتقل کرد. • y = f(2) % = 26 • y = g(2) % = 35 • minimum = fminbnd(f, -5, 5); % = -0.3333

  7. [ادامه] توابع سفارشی ezplot(f); % Plot f over a range of x hold on; plot(2, f(2), 'd'); % Plot a marker at (2, f(2)) plot(minimum, f(minimum), 's'); text(minimum, f(minimum) - 2, 'Minimum'); h = ezplot(g); set(h, 'color', 'red') % Plot g over a range of x plot(2, g(2), 'rd'); % Plot a marker at (2, g(2)) hold off;

  8. ساختن توابع سفارشی با داشتن حالت داخلی >> type makecounter.m function countfcn = makecounter(initvalue) currentCount = initvalue; countfcn = @getCounter; function count = getCounter % Increments the 'currentCount‘ currentCount = currentCount + 1; count = currentCount; end end

  9. [ادامه] توابع سفارشی با حالت داخلی >> counter1 = makecounter(0); >> counter2 = makecounter(10); >> counter1 % = 1 >> counter1 % = 2 >> counter2 % = 11 >> counter1 % = 3 >> counter2 % = 12

  10. خواندن فایلهای متنی با فرمت دلخواه • load % Variables from .MAT file • fread(.) % StrRead(.) for string • fscanf(.) % SScanf(.) for string • fgets(.) % newline included • fgetl(.) % newline NOT included • textread(.) % Fixed Format • textscan(.) % Variable Format

  11. تابع textscan(.) • تنظیم فرمت فایل • باز کردن فایل متنی برای خواندن • خواندن خطوط مقدماتی • خواندن بلوکها • بستن فایل متنی • تعداد بلوکهای خوانده شده • بررسی داده ها

  12. مثال: فایل متنی test80211.txt • بعد از 4 خط مقدمه، فایل از یک بلوک داده تشکیل شده است که به فرمت زیر می باشد: • دو خط توضیحات • پارامتر m • جدول داده ها به شکل p * m • تمام داده های خوانده شده در آرایه سلولی قرار داده می شود.

  13. [ادامه] مثال fid = fopen('test80211.txt', 'r'); % Open text file % Read strings delimited by a carriage return InputText = textscan(fid, '%s', 4, 'delimiter', '\n'); Intro = InputText{1}; disp(Intro);

  14. [ادامه] مثال – خواندن بلوک • خواندن هر بلوک: • خواندن عنوان • خواندن نام جدول • خواندن سرستون • خواندن داده ها

  15. [ادامه] مثال – کد Block = 1; % Initialize block index while (~feof(fid)) % For each block... % Read header line InputText = textscan(fid, '%s', 2, 'delimiter', '\n'); HeaderLines{Block, 1} = InputText{1}; InputText = textscan(fid, 'Num SNR=%f'); % Read parameter value NumCols = InputText{1}; % Read data block: FormatString = repmat('%f', 1, NumCols); % Create format string InputText = textscan(fid, FormatString, 'delimiter', ','); % Convert to numerical array from cell: Data{Block, 1} = cell2mat(InputText); [NumRows, NumCols] = size(Data{Block}); % Size of table % Read and discard EOB marker ('EOF' in this case): eob = textscan(fid, '%s', 1, 'delimiter', '\n'); Block = Block + 1; % Increment block index end

  16. [ادامه] مثال – کد 2 fclose(fid); NrOfBlocks = Block - 1 % How many blocks ? % Display Block #9 : Block = 9; disp(HeaderLines{Block}); disp(['SNR' sprintf(' %d', Data{Block, 1}(1, 2:end))]) format short e % Use exponential format disp(' '); disp(Data{Block, 1}(2:end, 2:end)); '* Indoor0' '* SNR Vs test No' SNR -7 -6 9.0600e-007 6.7100e-007 3.1700e-007 3.5400e-007 2.8600e-007 1.9600e-007 1.4800e-007 7.3400e-007 3.9500e-008 9.6600e-007 7.9600e-007 7.8300e-007 4.0000e-007 8.8100e-007 3.0100e-007 2.9700e-007

  17. نمایش نمودار دو بعدی XY plot

  18. تابع plot x = 0:0.05:5; Y = sin(x .^ 2); plot(x, y);

  19. تابع bar x = -2.9:0.2:2.9; bar(x, exp(-x .* x));

  20. تابع stairs x = 0:0.25:10; stairs(x, sin(x));

  21. تابع errorbar x = -2:0.1:2; y = erf(x); e = rand(size(x)) / 10; errorbar(x, y, e);

  22. تابع polar t = 0:.01:2*pi; polar(t, abs(sin(2 * t) .* cos(2 * t)));

  23. تابع stem x = 0:0.1:4; y = sin(x .^ 2) .* exp(-x); stem(x, y)

  24. مثال – رسم سری فوریه t = 0:.1:10; y = sin(t); plot(t, y); y = sin(t) + sin(3 * t) / 3 + sin(5 * t) / 5 + sin(7 * t) / 7 + sin(9 * t) / 9; plot(t, y);

  25. [ادامه] مثال – رسم سری فوریه t = 0:.02:3.14; y = zeros(10, length(t)); x = zeros(size(t)); for k=1:2:19 x = x + sin(k * t) / k; y((k + 1) / 2, :) = x; end plot(y(1:2:9, :)') title('The building of a square wave: Gibbs'' effect')

  26. [ادامه] مثال – رسم سری فوریه surf(y); shading interp axis off ij

  27. نمایش نمودار سه بعدی XYZ plot

  28. توابع رسم سه بعدی z=peaks(25); %%% mesh(z); colormap(hsv) surf(z); colormap(jet); surfl(z); shading interp; colormap(pink); contour(z,16); colormap(hsv)

  29. مقدمه تصویر تصاویر و ماتریس ها

  30. انواع تصویر • Black & White (B/W) • Grayscale • Colorful • Color Index (PALETTE) • Color Value • RGB (additive) • CMYK (subtractive) • HSI (HSV) (Hue Saturation Intensity) • Ia*b* • …

  31. تابع image(.) و colormap(.) X = spiral(8); image(X); colormap(gray); %%% colormap(hsv); %%% colormap(hot); 43 44 45 46 47 48 49 50 42 21 22 23 24 25 26 51 41 20 7 8 9 10 27 52 40 19 6 1 2 11 28 53 39 18 5 4 3 12 29 54 38 17 16 15 14 13 30 55 37 36 35 34 33 32 31 56 64 63 62 61 60 59 58 57

  32. تابع rgbplot(.) برای مشاهده نمودار نگاشت رنگ: rgbplot(S)

  33. توابع خواندن و نوشتن تصویر imread

More Related