Help with for loops and switch statements involving strings

1 view (last 30 days)
hi guys, I posed this elsewhere that I now believe was the wrong place to ask, so I'm re-posting here.
Long story short, I've been working at this for several hours and have not made any progress. I even got help from a friend and I still can't do this problem. Any help would be greatly appreciated. I am able to do this problem, but not using for loops and switch statements. I will copy and paste the problem:
Problem 3: MATLAB treats a string as a vector of characters. For example, if stringA
= 'Test', then stringA(1) = 'T', stringA(end) = 't' and length(stringA) = 4. In this exercise,
you will use for loops and switch statements to examine a string. Download the
file stringA.mat from TED and load it into MATLAB. The file contains a string named
stringA.
(a - c) How many times do the strings 'AT', 'CT', and 'GA' appear in stringA individually
? Put the answers into p3a, p3b, and p3c, respectively.
(d - f) How many times do the strings 'ATC', 'TAG', and 'GCT' appear in stringA
individually ? Put the answers into p3d, p3e, and p3f, respectively.
This is the string:
ATCGATTGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCATCGATTGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGGAGCTCTAGCGCTCTAGCGGCTCTAGCGCTCTAGCGGAGTGAGCTCTAGCGATCGATTGAGCTCTAGCGTGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCATCGATTGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGGAGCTCTAGCGCTCTAGCGGCTCTAGCGCTCTAGCGGAGTGAGCTCTAGCCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCATCGATTGAGCTCTAGCGATCGATTGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGCTCTAGCGGAGCTCTAGCGATCGATTGGAGCTCTAGCGCTCTAGCGGCTCTAGCGCTCTAGCGGAGTGAGCTCTAGC
Once again, any help is much appreciated.

Answers (1)

Walter Roberson
Walter Roberson on 8 May 2015
thissubstring = 'AT';
switch thissubstring
case 'GA'
disp('So you got a GA');
case 'AT'
disp('So you got a AT');
end
  2 Comments
Stephen23
Stephen23 on 9 May 2015
Edited: Stephen23 on 12 May 2015
@marco garcia: Whoever wrote the question was kind enough to tell you how to do this inside the question itself. Look at how they use indexing to extract specific elements of the string. You can simply do this in a loop too. You will also need to count how many times each of those substrings occur!

Sign in to comment.

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!