橘子王
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Matlab 教學(三) > 此篇內容為還沒有接觸matlab的初學者所寫,作者也是新手,資料來源於網路,有錯的話還請指正 > [Matlab入門教學(一)](https://hackmd.io/5N3j2unnQA-SS53txfTsXg?view) > [Matlab入門教學(二)](https://hackmd.io/rJgLH9x6RQqACdkPzGvT5w) ## Random & Loops ![Example_21](https://hackmd.io/_uploads/B1ZeYyS_R.png) ```py= #script % Random and Loops % Section 1 clc,clearvars A = randi(5,1,10) num3 = sum(A == 3) if sum(A == 3) >= 3 disp('wow!') end %% Section 2 clc,clearvars x = 10 ``` * ```randi(x,y,z)```為產生隨機整數的function,x表示最大值,生成y*z矩陣的數量 * ```if ... end```if一定要end結尾,軟體才知道要跑到哪。if後方即為條件,條件成立才執行下列程式碼,不成立則跳過。上方的意思為:若A矩陣內,3出現的次數大於等於3次,則print出wow! * %%為分段的意思,可以將script分段執行,RUN的旁邊有run section,點擊即可分段執行 ```py= # script2 % Random and Loops % If statement clc,clearvars A = randi(5,1,1000000); num3_if = sum(A == 3); if num3_if >= 0.2*length(A) disp('wow!') end % For loop num3_for = 0; for i = 1:length(A) if A(i) == 3 num3_for = num3_for +1; end end if num3_if >= 0.2*length(A) disp('wow!') end ``` * 此段程式碼將比大小的過程分成兩種方法:for或if * ```for```中,後方的值會隨運作次數而改變,此處為從1一直加到length(A)為止,for回圈中的i值會隨著改變。如果A(i)等於3的的話,num3_for就加一 * 上方用if、下方for,因為要達成的目標相同,所以wow!出現或消失的時機點要相同 ![Example_23](https://hackmd.io/_uploads/Bk6WKgBuR.png) :::info 可使用tic、toc來計算程式執行時間。tic放開頭、toc放結尾 ::: ![Example_24](https://hackmd.io/_uploads/SJZrseBu0.png) ## 如何命名 :::danger MATLAB names must start with a letter and contain only letters, numbers, or underscores ::: * 不能用數字做開頭 * 可以用底線或是大小寫來區分變數 ## While Loops ```py= #script % While Loops clc,clearvars z = 100; while z > 75 disp(sqrt(z)) z = z-1; end disp('loop end') ``` * ```while```為通常執行,裡面的code只要條件成立的話就會持續執行,如果條件沒設好,容易造成程式崩潰 ## Custom Function ![Example_25](https://hackmd.io/_uploads/HJ9cFWHuA.png) ![Example_26](https://hackmd.io/_uploads/SJhyoSU_R.png) * 點選左上角New->Function 即可新增想要的function(有點類似C語言中Project的方式)。要記得儲存在相同資料夾中 ```py= #main % While Loops clc,clearvars z = 100; reduce_z(z) **************************** #function function [z_final] = reduce_z(z_initial) z=z_initial; while z > z_initial/2 z = z-1; end z_final = z; end ``` * function可依照不同需求有不同輸入,但要記得輸入變數數目要相同 * 輸出用中括號、輸入用小括號、function名稱則落在後方 --- 參考資料 >1.[MATLAB Crash Course for Beginners](https://youtu.be/7f50sQYjNRA?si=tSxig57n6B59pO08) 進階自修 >[Matlab 簡易教學](https://hackmd.io/@FbUJsF5qTbyirb8qlvu2Fw/Sktejk7hc#:~:text=%E9%97%9C%E6%96%BCMatlab%201%20Matlab%20%E7%B0%A1%E6%98%93%E6%95%99%E5%AD%B8%202%20%E9%97%9C%E6%96%BCMatlab%20%E9%96%8B%E5%A7%8B%E4%BD%BF%E7%94%A8%20%E4%BB%8B%E9%9D%A2%E4%BB%8B%E7%B4%B9,plot%20%28stem%29%20%E5%AE%A2%E8%A3%BD%E5%8C%96%20%E5%85%B6%E4%BB%96%E5%AE%A2%E8%A3%BD%20%E8%AA%AA%E6%98%8E%E6%96%87%E5%AD%97%20%E5%AE%A2%E8%A3%BD%E7%AF%84%E4%BE%8B%204%20%E5%8F%83%E8%80%83%E8%B3%87%E6%96%99)

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully