Matlab Basics and Advanced Techniques for Efficient Programming

Matlab Basics and Advanced Techniques for Efficient Programming
Slide Note
Embed
Share

Discover the fundamentals of Matlab programming through basic and advanced commands. Learn about data types, classes, vectorization, distributed processing, indexing, and more. Explore practical examples and useful tips for optimizing your Matlab code. Dive into classes, inheritance rules, and built-in Matlab classes to enhance your understanding of programming concepts. Enhance your skills with insights on vectorization, matrix calculations, and distributed processing in Matlab. Uncover the power of efficient programming techniques in Matlab for smoother workflow and faster results.

  • Matlab Basics
  • Advanced Techniques
  • Efficient Programming
  • Vectorization
  • Distributed Processing

Uploaded on Apr 19, 2025 | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. FitLike Matlab basics Lionel Broche, EURELAX training school, Pavia, 19/02/2019

  2. Introduction Basic commands Concatenation Data types A bit advanced Classes Handles Vectorising Less basic commands Logical indexing Distributed processing: arrayfun/cellfun More advanced Local workspaces/nested functions Caller/Listener

  3. Basic commands Cells c{1} = 4 c{2} = 6 c{:} ones(c{:}) Content Array D = [c c]

  4. Basic Commands Concatenation m = [1, ones(1,3), 4] s = ['Make' num2str(1) ' ' char(87) 'ish ] Arrays: check size c = {'Anything' eye(5) @(x)size(x)} String: check type d = {'One more thing } Cell: quite free All = [c,d]

  5. Indexing Numerical e = eye(4); [l,c] = find(e>0); for i = 1:4 result(i) = e(l(i),c(i)); end Logical result = e(e>0); Faster, cleaner

  6. Vectorisation result = e(e(:)>0); Matrix calculation is fast with Matlab open autumn.tif mask = abs(autumn>200); autumnish = autumn.*uint8(mask); Imshow(autumnish) Make everything a matrix Make array: e(:) Reshape Use dot opertors autumn(abs(autumn(:))>200) = 0;

  7. Distributed processing h = arrayfun(@(x,y) plot(x,y),arrayX,arrayY) When you cannot vectorise, don t use FOR loops h = cellfun(@(x,y) plot(x,y),cellX,cellY) arrayfun cellfun list = arrayfun(@(n) eye(n),[1:10], 'UniformOutput',false); May need UniformOutput to false Produces a cell array

  8. Classes Definition open ModelTemplate.m Properties Methods Constructor Change class name Change file name Change constructor name Listeners Properties type may be set Change the model Using the @ symbol

  9. Classes Inheritance Rules Multiple parents Build-in Matlab classes DataUnit2DataUnit DispersionModel DataFit

  10. Classes Handles open DataUnit.m One instance only b1 = Bloc; Similar to pointers b2 = b1; Careful on deletion! b2.mask = false;

  11. Classes array of objects Instantiating classes [data, parameter] = readsdfv1('Dataset1_1.sdf'); Objects relaxlist = openRelaxObj('Dataset1_1.sdf','data ) Can access several properties matlab.mixin.Heterogeneous Returns cells/arrays

  12. Local workspace Nested function open DataFit.m Persistent functions Find setFixedParameter Avoids using eval Easier to debug

  13. Events open FitLike.m Listener Find ThrowMessage FitLike. throwMessage Caller FileManager. throwWrapMessage FitLike.open

More Related Content