Recommended problems
1. problem: Consider the following text: A neuron or, also known as a neurone, is an electrically excitable cell that receives, processes, and transmits information through electrical and chemical signals. These signals between neurons occur via specialized connections called synapses. Neurons can connect to each other to form neural networks. Neurons are the primary components of the central nervous system, which includes the brain and spinal cord, and of the peripheral nervous system, which comprises the autonomic nervous system and the somatic nervous system.
Create a variable called st, which contains this text as a string. Find out
- how many characters are in the text
- how many letter are there (look for a suitable function in the documentation)
- what is the most frequent letter?
st='A neuron or, also known as a neurone, is an electrically excitable cell that receives, processes, and transmits information through electrical and chemical signals. These signals between neurons occur via specialized connections called synapses. Neurons can connect to each other to form neural networks. Neurons are the primary components of the central nervous system, which includes the brain and spinal cord, and of the peripheral nervous system, which comprises the autonomic nervous system and the somatic nervous system.'; %% First question: length(st) %527 %% Second question sum(isletter(st))% 439 %% Third question stl=lower(st); numberofletter=zeros(1,26); for i=stl if isletter(i) numberofletter(double(i)-96)=numberofletter(double(i)-96)+1; end end [value, position]=max(numberofletter); char(position+96) % 'e'
2. problem Make a function called ceasarS(s), which takes a string as an input. The output is a string, where every letter is shifted by one in the abc, expect for z, which is changed to a. Also write the decoding function.
For the coding part:
function out=ceasarS(s) out=s; for i=1:length(s) if isletter(s(i)) if s(i)=='z' out(i)='a'; elseif s(i)=='Z' out(i)='A'; else out(i)=char(double(s(i))+1); end end end
For decoding:
function out=ceasarD(s) out=s; for i=1:length(s) if isletter(s(i)) if s(i)=='a' out(i)='z'; elseif s(i)=='A' out(i)='Z'; else out(i)=char(double(s(i))-1); end end end
3. problem: Write a function called findOut(s), which takes a string (which is the name of an excel file) as input. The outputs are the number of numbers in the excel file, and the minimum and maximum of them.
function [nnnumber, maxnumber, minnumber]=findOut(s)
allnumbers=xlsread(s);
nnumber=size(allnumbers,1)*size(allnumbers,2);
maxnumber=max(max(allnumbers));
minnumber=min(min(allnumbers));
4. problem Write a function called swapP(v,a,b), which takes a v vector, and two doubles as input. The output is a modified v: every element in v, which equals to a should be exchanged by b. If the function was called swapP(v,a), then every element equals to a should be exchanged to 1, if it was called swapP(v), then every 0 should be changed to 1.
function out=swapP(v,a,b) if nargin==2 b=1; elseif nargin==1 a=0; b=1; end v(v==a)=b; out=v;