{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

# Lab07 - Riti Gupta 20249537 Section 22 Lab 07 1.1 Character...

This preview shows pages 1–4. Sign up to view the full content.

Riti Gupta 20249537 Section 22 Lab 07 1.1 Character Arrays >> A='cat' A = cat >> B=[A, 'erpillar'] B = caterpillar >> C=B C = caterpillar >> C(1:length(A))='dog' C = dogerpillar >> class(C) ans = char >> B==C ans = Columns 1 through 10 0 0 0 1 1 1 1 1 1 1 Column 11 1 >> strcmp(B,C) ans = 0 1.2 Cell Arrays >> A={54 'cat'} A = [54] 'cat' >> B=A(1) B = [54] >> C=A{1} C = 54

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
>> class(B) ans = cell >> class(C) ans = double The difference between B and C is that B is a cell whereas C is a number, or double. Using the squiggly bracket tells MATLAB to take the components inside of the cell. In B, since only parentheses are used, MATLAB tells you what the first object of A is; a cell. You need squiggly brackets to open up the cell to retrieve what is inside of it. >> D={A 'dog' B} D = {1x2 cell} 'dog' {1x1 cell} a. >> D{2} ans = dog b. >> D{1}{2}(3) ans = t 1.3 Structure Arrays >> student student = 1x2 struct array with fields: name section >> student(1) ans = name: 'Chet' section: 14 >> student.name ans = Chet ans = Trevor >> student(2).section ans = 15 >> class(student)
ans = struct >> class(student(1)) ans = struct >> class(student(1).name) ans = char >> student(3).name='Chris'; >> student(3).section=11;

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}