Question

After the following script is executed, what is the value of max(c)? s = 'ABAABAABAB'; c(1:3)=0;...

After the following script is executed, what is the value of max(c)?

s = 'ABAABAABAB';

c(1:3)=0;

for i=1:length(s)-1

switch s(i:i+1)

case 'AA'

c(1) = c(1)+1;

case 'AB'

c(2) = c(2)+1;

otherwise

c(3) = c(3)+1;

end

end

Please include a detailed explanation of how you got the answer.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

ABAABAABAB

KEEPING C(1:3)=0

SO ABAABAB

LENGTH(S)=7

SO I=1:6

SWITCH S(6:7) IE AB //INDEXING FROM 0

C(2)=B+1

Add a comment
Know the answer?
Add Answer to:
After the following script is executed, what is the value of max(c)? s = 'ABAABAABAB'; c(1:3)=0;...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 4 CLO3 The following Python script implements an algorithm to find and prints the max value in a list of values. MAX 0 def MaxVal (Ist): for i in Ist: if( MAX < i): MAX = i return (MA...

    Question 4 CLO3 The following Python script implements an algorithm to find and prints the max value in a list of values. MAX 0 def MaxVal (Ist): for i in Ist: if( MAX < i): MAX = i return (MAX) Marks (20,24,26,19,5,31,24,32,32,45 print (MaxVal (Marks) a. Express the number of operations in terms of a function f(n), where n is the input size. (1 Mark) b. What is the total number of operations in the for loop of the algorithm...

  • matlap Question 1 1. Consider the following Matlab program 5 - (2 < 3) & (C2...

    matlap Question 1 1. Consider the following Matlab program 5 - (2 < 3) & (C2 > 3) 1 (1 - 0)) What is the final value of s? A. True B. *1 CO D. false 2- Which expression tests whether variable x is between (but not the same as) the values 5 and 10 (a) 5 <x< 10 (b) 5 <= x <= 10 (c) 5 < X & X > 10 (d) x < 10 & 5 <...

  • # After the if statement that follows is executed, what will the value of $discount_amount be?...

    # After the if statement that follows is executed, what will the value of $discount_amount be? $discount_amount; $order_total = 200; if ($order_total > 200) { $discount_amount = $order_total * .3; } else if ($order_total > 100) { $discount_amount = $order_total * .2; } else { $discount_amount = $order_total * .1; }         2         20         40         60 # To open a file in PHP, you use the _________ function.         fopen()        ...

  • should be in C language What is the output of the following segment of C code:...

    should be in C language What is the output of the following segment of C code: void CapsLetter (char* x, charl); int main() { char* text; text="This is some sample text."; CapsLetter(text, 'e'); printf("%s", text); return 0; سی void Caps Letter (char* x, char 1) { int i=0; while (x[i]!='\0') { if (x[i]==1) x[i]=1-32; } 1. This is som sample text. 2. THIS IS SOME SAMPLE TEXT. 3. This is some sample text. 4. this is some sample text. What...

  • MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown...

    MATLAB question Triangle Calculations (script with two anon functions) 0 solutions submitted (max: Unlimited) Consider a general triangle with side lengths a, b, and c and angles A, B, and C as shown below Write a script that does the following Define the following two anonymous functions and assign to the indicated Function Handles: 1. The function ThirdSide should accept the lengths of sides a and b as well as angle C in that order and use the Law of...

  • check) Determine the value in total after each of the following loops is executed for (i=i;...

    check) Determine the value in total after each of the following loops is executed for (i=i; i <-10; i-i+1) 3. (Desk a. total o total- total + 1i b. total 1; for (count 1; count <- 10, count count + 1) total = total * 2; c. total-0 for (i10; i 15: i i+ 1) total total ii d. total = 50; for (i -1: i <10; i i + 1) total = total - i; e. totall; for (icnt...

  • in c# 1- What is the output for total after the following segment of code executes?...

    in c# 1- What is the output for total after the following segment of code executes? int num = 3, total = 0; switch (num) {                case 1:                case 2:                               total = 5;                               break;                case 3:                               total = 10;                               break;                case 4:                               total = total + 3;                               break;                case 8:                               total = total + 6;                               break;                default:                               total = total + 4;                               break; } WriteLine("The value of total is " + total); The value displayed for total would be ....

  • What will be the value of x after the following code is executed? int x =...

    What will be the value of x after the following code is executed? int x = 5; while (x <50) { x += 5; } a) 50 b) 45 c) Infiniteloop d) 55 Given the following code segment: Scanner in = new Scanner (System.in); boolean done = false; while (!done) { int input = in.next(); if(input.equalsIgnoreCase("q")) done = false; } What will cause the loop to terminate? a) When the user enters -1 b) The loop will never terminate c)...

  • 2. What is the value of x alter the following code is executed # include<iostream> using...

    2. What is the value of x alter the following code is executed # include<iostream> using namespace std; int main int t-0, c- 0,x-3; while (c < 4) t=t+x; cout << x return 0; a) 3 b) 21 c) 24 d) 48 3. What is the output of the following code? # include<iostream> using namespace std; int main0 int a- 3; for (int i 5; i >0; i) a a+i cout << a << “ “ return 0; d) 8...

  • 1. Which of the following is declared correctly and will not result in an error, assuming...

    1. Which of the following is declared correctly and will not result in an error, assuming x 2 and y307 a) for (var j - 10; j < 80, - ) b) for (var 1 - x, c) for (var 1- d) for (var j = x 1 y ) + 5) -80 y: 1 - 5 /*) <= 80 • y: 1 -- 5) 2. The multiple-selection statement is used to handle decision making and can be used to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT