CRC.Press A Guide to MATLAB Object Oriented Programming May.2007 Episode 1 Part 5

Tham khảo tài liệu ' a guide to matlab object oriented programming episode 1 part 5', kỹ thuật - công nghệ, cơ khí - chế tạo máy phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 54 A Guide to MATLAB Object-Oriented Programming Code Listing 14 Public Variable Names in subref s Dot-Reference Case 1 2 switch index 1 .type case . 3 switch index 1 .subs 4 case Size 5 varargout 6 case ColorRgb 7 varargout 8 otherwise 9 error Reference to non-existent field . 10 index 1 .subs . 11 end 12 case 13 code to deal with cell array of index values 14 case 15 code to deal with cell array of index values 16 otherwise 17 error Unexpected of index 1 .type 18 end Modify the constructor by replacing all occurrences of mColorRgb with mColorHsv. Also in the constructor set the value for mColorHsv to rgb2hsv 0 0 1 . The modified constructor code is shown in Code Listing 15. Line 5 replaces mColorRgb with mColorHsv and assigns blue as the default color. Line 8 also represents an addition over the earlier constructor. Here we increase the superiority of cShape with respect to double because the interface definition overloads the associative operator mtimes. The change to subsref is almost as simple and is completely isolated inside the ColorRgb case. The modified ColorRgb case code is shown in Code Listing 16. Line 2 uses hsv2rgb Code Listing 15 Modified Constructor Using mColorHsv Instead of mColorRgb 1 function this cShape 2 this struct . 3 mSize ones 2 1 . scaled width height of bounding box 4 mScale ones 2 1 . width height scale factor 5 mColorHsv rgb2hsv 0 0 1 . H S V of border default blue 6 7 this class this cShape 8 superiorto double Code Listing 16 Converting HSV Values to RGB Values 1 case ColorRgb 2 rgb hsv2rgb 3 varargout mat2cell rgb 3 ones 1 size rgb 2 Changing the Rules . in Appearance Only 55 to convert private HSV values into public RGB values. The function will convert multiple HSV vectors by packaging each HSV 3-tuple as a row of the input matrix. Similarly each output RGB 3-tuple is returned as a row of the output matrix. In Line 2 supports a nonscalar this by concatenating HSV .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.